Page 1 of 1

Dynamic Form

Posted: Thu May 10, 2007 12:05 pm
by regX
I have a conundrum that was placed in my lap yesterday.

My company currently has a series of forms that is hosted by formsite.com, created by my company's previous webmaster.

The current input design goes something like this:

First | Last | Address | Zip
textbox1_1 | textbox1_2 | textbox1_3 | textbox1_4
textbox2_1 | textbox2_2 | textbox2_3 | textbox2_4
textbox3_1 | textbox3_2 | textbox3_3 | textbox3_4

etc...for apprx. fifteen rows. The problem is that it is not very usable. Sometimes the client user must submit two or even three instances of the same form in order to supply *all* of the information. In other words, there could be anywhere from 1-50 html table rows of inputs.

I would like to change the form format to something I think that would be a little more useable, but I am having trouble imagining all the working parts. An example of a new form would be:

First | textbox1
Last | textbox2
Address | textbox3
Zip | textbox4
Submit | AddAnother

"Submit" would complete the process while "AddAnother" would post the form to itself, store the data in a session, and clear the form for additional input. On process completion the values would be formatted and sent via email.

Validation of user input is a given, so this adds an additional "application state" -- an error state in which the client user is presented with things such as "The field is required" or "Can only contain 6-10 numbers" and the like.

So, my question: am I overlooking anything here, or forgetting some process? Am I making it overly complicated?

Any feedback is appreciated. I posted in this forum knowing that it *might* need to go in Design and Theory forum, but I wasn't sure so I posted it here.)

Posted: Thu May 10, 2007 2:37 pm
by Begby
There are two ways you can approach this, you can use a bunch of sessions and other tricks, or use javascript and name your input files using array syntax.

To keep it simpler I would strongly suggest doing the javascript thing. Name your inputs like contacts[1][address], contacts[1][first], contacts[2][address], contacts[2][first] etc. etc.

When you get the data in php, you can then do this

Code: Select all

// put in some error checks here and what not

$contacts = $_POST['contacts'] ;

foreach($contacts as $contact)
{
  echo $contact['first'] ;
  echo $contact['last'] ;
}
So now its just matter of using some fancy javascript to add new form fields to the page dynamically and then just naming the fields correctly.

Posted: Thu May 10, 2007 3:52 pm
by regX
Gotcha...thanks for the tip. Using JavaScript will save on some bandwidth too.