0
votes

I have my form in my action:

$this->form = new SomeForm($this->data);

the form has a bunch of fields I don't need for one action but has stuff I need for another action. What is the best way to handle this? Create an individual form for each necessity or dynamically remove fields when I instantiate it as above?

Thanks

2
Do you need to call the same form through different actions showing different fields number or all fields with different default values (that is or nothing or got by action)? - macgyver
I plan on showing different number of fields through the different actions - Paul

2 Answers

0
votes

It sounds like you are doing a multi-part form.

I assume that you want to validate all the values submitted in your form, but just not save them.

  1. Its sounds like you are doing an abstract form, so don't extend a base object form, rather extend BaseForm.
  2. Don't unset the values, use the form to validate them, even if they're going to be used later.
  3. They are saved to the form object, so you can use that to pass values to your next action, so this is helpful, plus they are validated.
  4. Override doSave() in the form to save the objects of the form you want to save.
0
votes

In my opinion for this case, extending the form to each need and applying, through the override of the setup, selectively the unset instruction, you get a code a little more readable and maintainable.