This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » General discussion » [SOLVED] Edit single value for multi value table in seperate single field form
[SOLVED] Edit single value for multi value table in seperate single field form [message #97108] Sun, 11 April 2010 01:12 Go to next message
janismucenieks  is currently offline janismucenieks
Messages: 31
Registered: March 2010
Location: Latvia
Member
Hello!

I have table with many values and all work well in automatically generated form that allows to edit all values in single form.
How can I make separate form that would allow to edit just one field and leave all other values unchanged.
I did manage to make form that has only one field, yet when saving changes that form also sets all other fields to null.
I have CarForm.class.php (generated by symfony) and CarNoteForm.class.php (handmade).
In CarNoteForm.class.php I have
class CarNoteForm extends BaseCarForm
{
  public function configure()
  {
	$this->useFields(array('note'));
  }
}

But since it uses same _form partial, saving changes to "note" field deletes all other fields for particular Car.

What to do or what am I doing wrong?
Thank You!
Janis

[Updated on: Sun, 18 April 2010 17:18]

Re: Edit single value for multi value table in seperate single field form [message #97122 is a reply to message #97108 ] Sun, 11 April 2010 14:42 Go to previous messageGo to next message
janismucenieks  is currently offline janismucenieks
Messages: 31
Registered: March 2010
Location: Latvia
Member
irrelevant

[Updated on: Sun, 18 April 2010 17:15]

Re: Edit single value for multi value table in seperate single field form [message #97256 is a reply to message #97122 ] Tue, 13 April 2010 11:56 Go to previous messageGo to next message
janismucenieks  is currently offline janismucenieks
Messages: 31
Registered: March 2010
Location: Latvia
Member
irrelevant

[Updated on: Sun, 18 April 2010 17:16]

Re: Edit single value for multi value table in seperate single field form [message #97300 is a reply to message #97256 ] Wed, 14 April 2010 02:27 Go to previous messageGo to next message
janismucenieks  is currently offline janismucenieks
Messages: 31
Registered: March 2010
Location: Latvia
Member
irrelevant

[Updated on: Sun, 18 April 2010 17:16]

Re: Edit single value for multi value table in seperate single field form [message #97556 is a reply to message #97300 ] Sun, 18 April 2010 16:57 Go to previous message
janismucenieks  is currently offline janismucenieks
Messages: 31
Registered: March 2010
Location: Latvia
Member
With help from others, way too much frustration and experimental coding I have working solution. It looks like this:

CarForm.class.php:
class CarForm extends BaseCarForm
{
  
  public function configure()
  {	
	if ($this->getOption('editnote'))
		$this->useFields(array('note'));
	else 
		unset( $this['created_at'], $this['updated_at'] );
	
  }
}

'editnote' in $this->getOption('editnote') is variable passed from actions.class.php

actions.class.php:
  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($car = Doctrine::getTable('Car')->find(array($request->getParameter('id'))), sprintf('Object car does not exist (%s).', $request->getParameter('id')));
	
	$this->form = new CarForm($car, array('editnote'=>$request->getParameter('editnote')));	
  }

'editnote' in $request->getParameter('editnote') is variable passed from url

Same in executeUpdate in actions.class.php:
  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($car = Doctrine::getTable('Car')->find(array($request->getParameter('id'))), sprintf('Object car does not exist (%s).', $request->getParameter('id')));
    $this->form = new CarForm($car, array('editnote'=>$request->getParameter('editnote')));

    $this->processForm($request, $this->form);

	$this->setTemplate('edit');
  }


in _form.php
<form action="<?php echo url_for('jurp/'
.($form->getObject()->isNew() ? 'create' : 'update')
.(!$form->getObject()->isNew() ? '?id='
.$form->getObject()->getId() : '')
.($form->getOption('editnote') ? '&editnote='.$form->getOption('editnote') : '')) ?>"
method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>

".'&editnote='.$form->getOption('editnote')" is added to url_for. So that 'editnote' can be retrieved for next form.

Finally the url in view looks like this:
<a class = "rediget" href = "<?php echo url_for('car/edit?id='.$car->getId().'&editnote='.true) ?>">Edit note</a>
 OR
<a class = "rediget" href = "<?php echo url_for('jurp/edit?id='.$jur_p->getId().'&editnote='.false) ?>">Edit whole table</a>


The same manner You can pass not just bolean to get more options available at form class configure.

Hope this helps!

Janis

[Updated on: Sun, 18 April 2010 19:12]

Previous Topic:synchronize routing.yml and JavaScript, your practice?
Next Topic:symfony propel:build-forms not generating complete widgets/validators
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software