vavi2s Posted April 30, 2011 Share Posted April 30, 2011 ok ive searched everywhere online for a webform that is in 2 or more parts... so the first page passes variables to the second page then saves info for next page to submit all info from both pages of application to a server etc. ideally my page would look like this... page 1: small form with 3 fields: 1. type of loan: [dropdown menu] a. Cashout refinance b. Purchase 2. Property type: [dropdown menu] a. single family b. multi-unit, etc. 3. Property State: [dropdown menu] a. states....... [Next Page] <---Button page 2: a few more fields: (for example:) 1. Approximate credit score [dropdown menu] a. 650-700 etc.... 2. Phone number [textbox] 3. email address [textbox] [submit button] I know its possible, i just need to be put on the path... any help is much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/ Share on other sites More sharing options...
wildteen88 Posted April 30, 2011 Share Posted April 30, 2011 Because PHP does not pass on variables page to page. You can save the posted data into a session. So when you submit the first form to your second form save the posted data into a session, eg $_SESSION['step1_data'] = $_POST; After you have saved the posted data. Display your next form. On your final page you can work with the data you have collected. Here is an example step1.php <form action="step2.php" method="post"> <p> Loan Type: <select name="loanType"> <option>Loan Type 1</option> <option>Loan Type 2</option> <option>Loan Type 3</option> </select> </p> <p> Property Type: <select name="peopertyType"> <option>Property Type 1</option> <option>Property Type 2</option> <option>Property Type 3</option> </select> </p> <p> Property State: <select name="peopertyState"> <option>Property State 1</option> <option>Property State 2</option> <option>Property State 3</option> </select> </p> <p><input type="submit" name="step1_submit" value="Continue →" /></p> </form> step2.php <?php session_start(); if(isset($_POST['step1_submit'])) { $_SESSION['step1_data'] = $_POST; /* add all data from step1 to session variable */ ?> <form action="step3.php" method="post"> <p> Credit Score: <select name="creditScore"> <option>500 - 600</option> <option>600 - 700</option> <option>800 - 900</option> </select> </p> <p> Phone Number: <input type="text" name="phoneNumber" /> </p> <p> Email Address: <input type="text" name="emailAddress" /> </p> <p><input type="submit" name="step2_submit" value="Continue →" /></p> </form> <?php } else { ?> Please fill in <a href="step1.php">Step 1</a> <?php }; ?> step3.php <?php session_start(); if(isset($_POST['step2_submit']) && isset($_SESSION['step1_data'])) { echo "Your data: <h1>Step 1</h1>"; foreach($_SESSION['step1_data'] as $field => $value) { if($field != 'step1_submit') echo "<p><b>$field</b> = $value</p>"; } echo "<h1>Step 2</h1>"; foreach($_POST as $field => $value) { if($field != 'step2_submit') echo "<p><b>$field</b> = $value</p>"; } } else { echo 'Fill in <a href="step1.php">Step 1</a>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1208598 Share on other sites More sharing options...
vavi2s Posted April 30, 2011 Author Share Posted April 30, 2011 I tried that and i got this message on page 2 Parse error: syntax error, unexpected $end in /home/pr084660/public_html/form/try/step2.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1208769 Share on other sites More sharing options...
wildteen88 Posted April 30, 2011 Share Posted April 30, 2011 Strange whey you're getting that error when on line 18 it is the the <p> tag. Have you modified the script in any way? Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1208803 Share on other sites More sharing options...
vavi2s Posted April 30, 2011 Author Share Posted April 30, 2011 oh nevermind i didnt copy the last part it cut off for some reason, it works!! but how would i get that to email the results to a designated email? Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1208805 Share on other sites More sharing options...
wildteen88 Posted April 30, 2011 Share Posted April 30, 2011 PHP can send emails with the mail function. Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1208807 Share on other sites More sharing options...
vavi2s Posted May 1, 2011 Author Share Posted May 1, 2011 ok i will look it up thanks so much!! i tried several approaches and this is the first one that worked!! Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1208919 Share on other sites More sharing options...
vavi2s Posted May 2, 2011 Author Share Posted May 2, 2011 great, i cant figure out how to send ALL the results by email, its only sending the step2 results not from step1. sorry as you can see i am fairly new to php :-\ Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209312 Share on other sites More sharing options...
spiderwell Posted May 2, 2011 Share Posted May 2, 2011 post up the page that sends the email so we can see how you are trying to send the info.. Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209315 Share on other sites More sharing options...
vavi2s Posted May 2, 2011 Author Share Posted May 2, 2011 i got this code from a tutorial online haha <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'Results from Contact form'; // Your email address. This is where the form information will be sent. $emailadd = 'mail@rdsnetworks.net'; // Where to redirect after form is processed. $url = 'http://www.rdsnetworks.net/confirmation.html'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209316 Share on other sites More sharing options...
spiderwell Posted May 2, 2011 Share Posted May 2, 2011 that form is , as i suspected, only getting data from the $_POST array, and not including the stored data in the session object, you need to add that part to it. Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209318 Share on other sites More sharing options...
vavi2s Posted May 2, 2011 Author Share Posted May 2, 2011 thanks but im sure you can guess what my response is going to be... HOW?? I cant wait to be able to look at code like you guys and see whats wrong with it in a split second but for now I am the low man on the totem pole and need a boost. can you explain where I would add the missing variables thanks again Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209321 Share on other sites More sharing options...
spiderwell Posted May 2, 2011 Share Posted May 2, 2011 the 3rd page of code from wildteen does it, just change it to pass the data to the $text variable for your email instead foreach($_SESSION['step1_data'] as $field => $value) { if($field != 'step1_submit') echo "<p><b>$field</b> = $value</p>"; } Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209354 Share on other sites More sharing options...
vavi2s Posted May 2, 2011 Author Share Posted May 2, 2011 haha ok thank you for your help ill just have to search that out now I still am just going around in circles Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209494 Share on other sites More sharing options...
wildteen88 Posted May 2, 2011 Share Posted May 2, 2011 Have you tried writing the code yourself. It helps if you learn the basics of PHP. Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209511 Share on other sites More sharing options...
vavi2s Posted May 2, 2011 Author Share Posted May 2, 2011 in the process of learning it. having a tough time obviously but im sure everyone here was at my stage at some point, i just hope when I do get to that stage I can make the newbies feel as welcome as you guys have Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209514 Share on other sites More sharing options...
spiderwell Posted May 2, 2011 Share Posted May 2, 2011 Have you tried writing the code yourself. It helps if you learn the basics of PHP. hey what! why else did god invent the interwebz Quote Link to comment https://forums.phpfreaks.com/topic/235177-2-page-webform-passing-variables/#findComment-1209550 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.