Jump to content

dynamic form variables


karldesign

Recommended Posts

An array is possible when a form dynamically adds fields (or if php dynamically generates and outputs the form).

 

Instead of creating name="form_1", name="form_2", you just change it to name="form[]" or if you want to give them specific indexes name="form[1]", name="form[2]"

 

It makes no difference what name you generate but it makes a big difference in the form processing code on how easy it is to iterate over one method and not the other. Sequentially named variables/indexes require you to carry along how many of them there are. An array does not need that extra information.

 

Just because you could not get it to work, does not mean it does not work.

That type of code only works if the values are continuous. For a check box or radio button, where nothing will exist if they are not selected, the loop will stop on the first unchecked input and will never see the following fields. Arrays solve all problems like that.

And if you are looking for non-continuous stuff, there are other ways to do it. I've done it more than one way. My point is your saying "You should be using an array instead of sequentially named variables/indexes" is absolute, when there are many ways to do something. Which is why I asked to see his code.

 

You were taking a cocky attitude, when there may not have been issues with the way he was doing it. Until we see his code, there is no way of knowing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.