jazzman Posted February 25, 2007 Share Posted February 25, 2007 Hi all! I want to build a form in which there will be a button that allows to add an input field every time it is pressed. Can somebody please help me accomplish this? ??? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 25, 2007 Share Posted February 25, 2007 You need to use javascript if you want it so the page doesn't refresh. Quote Link to comment Share on other sites More sharing options...
jazzman Posted February 25, 2007 Author Share Posted February 25, 2007 Can someone please direct me to an explanation of how this can be done? Quote Link to comment Share on other sites More sharing options...
severndigital Posted February 25, 2007 Share Posted February 25, 2007 initially i would do it like this. 1. pass a hidden field that contains the current total of form fields. 2. when the button is pressed, post the hidden field and add 1. 3. run a while loop to display the results and decrease the hidden field by 1 until it reaches zero. 4. don't forget to post and echo the current form information so the user doesn't have to re-input. something like this which can probably be simplified, but to break it down I'll go through it. <? //get field $totalfields = $_POST['hiddenfield']; //add one $add1 = $totalfields + 1; //run while loop while($add1 > 0){ echo 'the form field data would go here. do not forget to echo the contents from the post.'; $add1 = $add1 - 1 ;//subtract 1 from the total until it reaches zero } //echo the hidden field + 1 to get next time. $hiddentotal = $totalfields + 1; echo '<input name="totalfields" type="hidden" value="' . $hiddentotal . '">'; ?> this should keep you from having to use JavaScript, but it will refresh the page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.