Dynamically adding inputs to a form with PHP?

Associate
Joined
29 Dec 2004
Posts
2,249
Morning,

I have a form that allows people in our small team to submit orders to a procurement person. One part form is built using a PHP loop as sometimes a person may need to order 1 item, sometime's 8 items and this is specified in the URL (form.php?itemamount=1, or =8).

Whilst this works, if somebody is filling the form out and they forget and want to add another item they loose everything they have typed in (as the page has to be reloaded with, for example, ?itemamount=2 rather than 1).

Getting to the point - is there a way i can dynamically add a group of fields (two select boxes, two textboxes, and two radio buttons to be exact) with one button that won't reload the entire page?

e.g

Name:
Contact:
_________________________
Item: (select box)
Quantity: (select box)
Reason: (textbox)
Type: (radio buttons)
Old Assets: (textbox)
_________________________

(add another item) <---- will add another bit of the form in the lines above!


I tried searching by the way...couldn't find anything that would dynamically add all the different types of fields i wanted...

Thanks!
 
Still had no luck, i don't think a Javascript solution will work for me as most of my form's fields are populated by including text files with PHP which doesn't work too well with Javascript. For example:

Code:
	echo '<td><strong>Item</strong> (*)</td>';
	echo '<td><select style="width:600px" name="theitem[]">';
	if($_POST['theitem'][$x]) echo '<option>' . $_POST['theitem'][$x] . '</option>';
	include('products.txt');
	echo '</select></td></tr>';

Is there anything out there i can use to dynamically add stuff like this, and not just simple code (most sites i have been looking at show you how to add something like a single textbox with no validation etc..!)

Anyone?!
 
Back
Top Bottom