php - Force Symfony to save the embedForm -
i have symfonyform has embedform. want save embedform if filled if main form empty. user can upload many photos wants 1 foo objekt. dont know how force symfony save embedform ?!
schema
foo: columns: title: {type: string(255), notnull: true} photo: columns: foo_id: {type: integer} filename: {type: string(255), notnull: true} caption: {type: string(255), notnull: true} relations: foo: alias: foo foreigntype: many foreignalias: photos ondelete: cascade
foophotoform:
$photo = new photo(); $photo->foo = $this->getobject(); $photoform = new photoform($photo); $this->embedform('newphoto', $photoform);
photoform:
$this->usefields(array('filename', 'caption',)); $this->validatorschema['filename'] = new sfvalidatorfile(...);
action:
protected function processform(sfwebrequest $request, sfform $form) { $form->bind($request->getparameter($form->getname()), $request->getfiles($form->getname())); if ($form->isvalid()) { $cms = $form->save(); } else { if(caption , filename not empty) { $form->saveembeddedforms(); } else { $this->getuser()->setflash('error', 'the item has not been saved due errors.', false); } }
forcing seems me trying hack normal execution make things work, dont recommend it, here options:
- my first approach problem using ajax allow users save specific part , not sending hole bunch of empty fields.
- you should modifie processform (general admin generator method takes care of saving form objects) action retrieve embbedform information request, create instance of embbed form , bind request information (only 1 of embbed form) validation take place. if valid save it.
check admin-generator code (stored in cache) in actions create or update, visualize bit more idea.
Comments
Post a Comment