Search code examples
symfony1symfony-1.4symfony-forms

Validating 2 forms in the action/view


I have 2 forms on a page, that I'd like to validate separately.

I have the following:

public function executeNew(sfWebRequest $request)
{
    $this->propertyForm = new AdminNewPropertyForm();
    $this->propertyCsvForm = new AdminNewPropertyImportForm();

    $this->processForm($request, $this->propertyForm, $this->propertyCsvForm);

}

protected function processForm(sfWebRequest $request, sfForm $propertyForm, sfForm $propertyCsvForm)
{
 if($request->hasParameter('property'))
 {
     if($request->isMethod('post'))
     {
         $propertyForm->bind($request->getParameter($propertyForm->getName()));
         if($propertyForm->isValid())
         {
             $propertyForm->save();
             $this->getUser()->setFlash('success', 'The property was successfully updated.');
         } else {
             $this->getUser()->setFlash('error', 'The property could not be saved.');
         }
     }
 } 
 else {
     if($request->isMethod('post'))
     {
         $propertyCsvForm->bind($request->getParameter($propertyCsvForm->getName()));
         if($propertyCsvForm->isValid())
         {
             $propertyCsvForm->save();
         }
     }
 }   

}

I am then displaying both forms in the view.

The problem is, I'm getting an error when passing the forms in processForm()

Strict standards: Declaration of propertyActions::processForm() should be compatible with that of autoPropertyActions::processForm()

Am I passing the forms correctly?

Thanks


Solution

  • As the error message says you are obviously not doing it correctly ;)

    As your propertyActions class extends an abstract class autoPropertyActions there are some strict standards on implementing the functions declared in the abstract class. That's why it's complaining that you have made some unexpected alterations.

    In fact - do you really have to use the processForm function? After all you are calling this function yourself, so you can call it whatever you like and the class won't complain then (as the original processForm will stay intact).