jadeoracle Posted December 15, 2007 Share Posted December 15, 2007 Hello! I'm new to PHP coding, and I'm stuck. I'm trying to code an order form that allows the user to add more fields if they need to. I have the order form display 5 item lines. Each line has a line number, item name box, and quantity box. If the user has more than 5 items to order, I have a button that says, "Add More Items". If the user presses that button another item line (or set of 5 more lines, doesn't matter) should appear at the bottom of the list, extending the form. How do I do this? ??? I'm thinking I need to use isset() to check is that "Add More Items" button has been pressed, and then unset() the button, but I'm not sure... Perhaps a checkbox would be better? The only way I understand so far is to retrieve form input is to use $_POST['formDataName'] but I technically don't want to send all the data yet, just add more fields. Like I said, I'm a beginner, so any help is greatly appreciated. The Uline site has an order form that extends, which is what I'm wanting to mimic: http://www.uline.com/EasyOrder.asp Of course, it seems that form is using JavaScript to pull off the adding of the new fields. I'm hoping I can use PHP to do the same ... if it's possible. Below is a stripped down basic version of what I have so far with my form. <form method="post" action="quickorder.php"> <table border="1"> <tr> <td>NO.</td> <td>ITEM NAME</td> <td>QUANTITY</td> </tr> <?php $counter = 1; function orderField () { global $counter; print "<tr>\n"; print "<tr>\n"; print "<td width=\"5\">$counter</td>\n"; print "<td><input type=\"text\" name=\"$item\" size=\"30\" /></td>\n"; print "<td><input type=\"text\" name=\"$quantity\" size=\"10\" /></td>\n"; print "</tr>\n"; } if ($counter == 1) { for ($x = 1; $x <= 5; $x++) { $item = "item" . $counter; $quantity= "quantity" . $counter; orderField (); $counter++; } } ?> <tr> <td colspan="3"> <input type="button" name="moreItems" value="Add More Items" /> <input type="submit" value="Submit Order" /> <input type="reset" value="Reset Form" /> </td> </tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
trq Posted December 15, 2007 Share Posted December 15, 2007 This whole thing would be best done using Javascript, not php. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 15, 2007 Share Posted December 15, 2007 you coudl do one of two things. you could use PHP as your asking and have the <add more items> button resubmit that page. then what you woudl do is add the values back intot eh field, and echo more fields form your PHP script. Using javascript, you would create new elements in thr form - probably using a name like <*** name = name_1> having "1" increment. then you could easily play with those names on the form handling page. Hope that helps to spell it out a little more. gdlk Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 http://www.quirksmode.org/dom/domform.html Should help you. Quote Link to comment Share on other sites More sharing options...
thenature4u Posted December 17, 2007 Share Posted December 17, 2007 register www.naukri.com, in registration(in 2nd page) u will find dynamically adding new form fields. see the view source code. he done using java script......... 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.