tapupartforpres Posted August 29, 2008 Share Posted August 29, 2008 Hello. I didn't know if this is a .php question. But I appreciate your comments. I have a form that people will fill out for an event. The person registering for the event has the option to have 8 guests. So depending on how many guests there are, it will give them that many fields to fill out for each guest. Hope that make sense. Is there a way to do that, or will I have to create a seperate page for each quantity of guests. This info is compiled and sent to paypal (and sent to the SQL file). Quote Link to comment Share on other sites More sharing options...
Wolphie Posted August 29, 2008 Share Posted August 29, 2008 I would recommend a little bit of nifty JavaScript. I would suggest having a form that displays only one text field, have a link or a button next to that text field so when users clicked it, you would append another text field and so on. For the PHP side of things, I would suggest making these into an array. I.e. <input type="text" name="guests[]" id="guests" /> Note the []! This will make "guests" an array. For example: echo $_POST['guests'][0]; // Guest 1 echo $_POST['guests'][1]; // Guest 2 // And so on.. Quote Link to comment Share on other sites More sharing options...
tapupartforpres Posted August 29, 2008 Author Share Posted August 29, 2008 That will work, but let me ask you this. Is there a way that when someone fills out the form, their information will be posted on the next page. So if they fill it out on the index page, it will auto fill out the form on the second page, if you know what I mean. Thanks Quote Link to comment Share on other sites More sharing options...
kratsg Posted August 29, 2008 Share Posted August 29, 2008 You can use sessions to store data while the user is browsing your site so that it could be recalled on any page at a later time. Quote Link to comment Share on other sites More sharing options...
KPH71 Posted August 29, 2008 Share Posted August 29, 2008 If I am understanding you correctly, you mean that you want to display the data from the form on the next page (if I am wrong please correct me as I may have misunderstood). This is extremely easy due to PHP's built in $_POST array. Each element of the forum has a 'name' attribute. (<input type="text" name="guests[]" />). This can be accessed by PHP like this (just as mentioned in a previous post): <?php echo $_POST['guests'][0]; echo $_POST['guests'][1]; ?> On the next page you can then make your form like this: <input type="text" name="guests[]" id="guests" value="<?php echo $_POST['guests']['0'];?>" /> If the user inputs a guest called Phil then this will output a text box with Phil written in it. A bit extra for you! You also mentioned before that you would have multiple guests, and would therefore want the same number of input boxes. To do this you could use PHP's foreach control structure. E.g.: <?php foreach ($_POST['guests'] as $value) { echo '<input type="text" name="guests[]" id="guests" value="'.$value.'" /><br />'; } ?> Be careful with this - you might choose to change the single and double quotes here - I have done this with singles for the echo statement and doubles for the html attributes. value=" '.$value.' " Take a look at that snippet of beofre. The red double quotes show the html attributes, the green single quotes end and start the string for the echo statement and the blue dots add on the next variable or string. If as the previous poster suggested, you want to have the information available on multiple pages as they move around, you should put this data into a PHP session. Quote Link to comment Share on other sites More sharing options...
tapupartforpres Posted August 31, 2008 Author Share Posted August 31, 2008 Almost. What I wanted to do was to post the registration info to the next page. Then depending on how many guests they had it would go to a page with that number of guests on it. So if they selected 5 guests from the drop down menu, then their info would post to the next page and then there would be 5 places for the guest names. Hope that clears it up. Quote Link to comment Share on other sites More sharing options...
tapupartforpres Posted August 31, 2008 Author Share Posted August 31, 2008 Sorry I am a newbie. I understand what you are saying. From the HTML form I am posting to the .php file. So in the .php file how do I tell it to proceed to the next page? Quote Link to comment Share on other sites More sharing options...
tapupartforpres Posted August 31, 2008 Author Share Posted August 31, 2008 Maybe this will clear it up. When the form is posted I want the name of the registration person filed out on the next page, then depending on the number of guests it will go to that coorisponding page. (Guests 1 - . So I have the standard info like "first_name", "last_name", etc. It is proceeding to the next page, but it is filling out the "<?php echo $_POST['first_name']['0'];?>" /> in the value field. I know I got this wrong, so if someone could help I would apprecite it. Thanks Quote Link to comment Share on other sites More sharing options...
KPH71 Posted September 27, 2008 Share Posted September 27, 2008 OK - best way to do this is probobly as follows <?php if(is_numeric($_POST['noofguests'])){ $number = intval($_POST['noofguests']); if ($number<1){die('Number cannot be less than zero');} for ($k=1; $k<$number; $k++){ echo '<input type="text" name="guests[]" /><br />'; } } else {die('Invalid Number of guests');} ?> 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.