Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically add forlm fields 1

Status
Not open for further replies.

mcquam

Technical User
Feb 26, 2007
89
GB
I have a form where one of the fields can have an unknown number of inputs. I need a way for php to count the fields that have been populated and offer a blank field if required. I currently have 20 input fields like this:
Code:
	<li><input type="text" name="ingredient[]" id="ingredient_1" size="80" value="<?php if (isset($_POST['ingredient'])) echo $_POST['ingredient']; ?>" /></li>
So I am looking for a way to create the list from the array field and also to presumably have the form to submit only the ingredient fields.
 
Assuming I understand what you need, PHP can't interact with the client, so there is no way for it know when a field has been populated. Unless the form is submitted to it.

You would need Javascript to check that all fields have been used and then have it create the additional field.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I concur with vacunita. You will need to submit the form and react appropriately or you will need Java Script (a client-side service) to monitor field content and populate more as needed.

-Geates
 
I thought it might be possible to make the form sticky and present it with an additional field each time?
 
Thanks, I've managed to do it with jquery.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top