Daryl Posted September 29, 2011 Share Posted September 29, 2011 I have a simple form which sends results (using php) to my email. It works fine. I want to make a similar form, and send the results not to email but to another web page, showing a summary of the form results, so user can check if all is entered correctly before continuing. Can anyone advise if this is possible and how. I am a real php beginner ... Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/ Share on other sites More sharing options...
aj123cd Posted September 29, 2011 Share Posted September 29, 2011 http://php.net/manual/en/function.header.php http://www.plus2net.com/php_tutorial/php_redirect.php Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1273979 Share on other sites More sharing options...
ZulfadlyAshBurn Posted September 29, 2011 Share Posted September 29, 2011 please post you current code. Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1273994 Share on other sites More sharing options...
Daryl Posted September 29, 2011 Author Share Posted September 29, 2011 I have a simple form which works for results sent to email, see below, if this helps This is what I have for the email (I deleted most of the fields for space reasons) : <form action="http://www.website.net/sendresultsrequest.php" method="post" name="form1" form> <h2>Name <br /> <span id="sprytextfield1"> <input name="name" type="text" class="formLINE" id="name" size="65" /> <span class="textfieldRequiredMsg">Please insert your name here</span></span></h2> <h2>Company<br /> <input name="company" type="text" class="formLINE" id="company" size="65" /> <span class="textfieldRequiredMsg">Please insert your company name here</span></span> </h2> <h2> <input name="send" type="submit" class="button" id="send" value="Submit" /> </h2> </form> And the php part here : <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'request'; // Your email address. This is where the form information will be sent. $emailadd = '[email protected]'; // Where to redirect after form is processed. $url = 'http://www.website.net/thankyou.htm'; // 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/248098-form-results-to-web-page/#findComment-1273995 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 What you need to do with that script is to output almost exactly what is being sent in the email. Along with the output, you will need to create a new form exactly as it was before but with all the elements hidden. After this has been achieved, give the user 2 options. One to continue and one to go back and make changes. Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1273998 Share on other sites More sharing options...
Daryl Posted September 29, 2011 Author Share Posted September 29, 2011 What you need to do with that script is to output almost exactly what is being sent in the email. Along with the output, you will need to create a new form exactly as it was before but with all the elements hidden. After this has been achieved, give the user 2 options. One to continue and one to go back and make changes. Thanks Buddski, this is exactly what I need - a new form with hidden elements How to I amend the php to send the results to a new page? I make the new page, same fields but make them hidden, that's clear - where do I edit the php : do I take away the email references and just leave a redirect page address (address of the new page)? Or I need to do something else? Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1273999 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 Ok so step 1: You create your form, lets say the page is form.php Once the user submits his information, you can send him to, verify_details.php verify_details.php example, this is very close to your original code but for display $text = "Please review and confirm your information before continuing:\n\n"; $space = ' '; $line = ' '; $new_form = array(); foreach ($_POST as $key => $value) { // This is what builds your hidden elements // $new_form[] = '<input type="hidden" name="'.$key.'" value="'.$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 = ' '; } // Output the $text, could probably be changed for display purposes // Start Again button doesnt do anything, call me lazy =) echo $text , '<form method="post" action="confirmed_results.php">' , join("\n",$new_form) , ' <input type="button" value="Start Again" /> <input type="submit" name="confirm" value="Im happy, lets continue" /> </form>'; Once the user has confirmed their results, it will take them to confirmed_results.php This page can be the existing script that you already have, I just made a middle man kinda Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1274006 Share on other sites More sharing options...
Daryl Posted September 29, 2011 Author Share Posted September 29, 2011 Oh, thank you for that I really appreciate. Though, I am quite OK at HTML web design, my php knowledge is limited to being able to do that results to email ... :-= So, just that I check I do exactly right . I make a normal HTML page with my original form. I set the form action. <FORM ACTION="http://www.website.net/sendresultsweb.php" METHOD="POST"> In the sendresults.php file I set : // Your email address. This is where the form information will be sent. $url = 'http://www.website.net/verify_details.php'; To I make the verify_details.php exactly as you have it, but for the hidden fields I write the original form field names ? Like this : ? // This is what builds your hidden elements // $new_form[] = '<input type="hidden" name="Customer_id"'.$key.'" value="'.$value.'" />'; $new_form[] = '<input type="hidden" name="Amount"'.$key.'" value="'.$value.'" />'; And this should display the results as the user typed in the original form? ?? I think that part is not right ...? Can I not make the verify_details.php page a HTML page with a HTML form with the fields as hidden names, would that work ... ?? Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1274014 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 First page form <FORM ACTION="verify_details.php" METHOD="POST"> The code I provided SHOULD be all working. Basically, Form 1 sends to my script; The form on my script then will send to your script; This line of code $new_form[] = '<input type="hidden" name="'.$key.'" value="'.$value.'" />'; will essentially grab all the fields from the original form and make them hidden automagically, you dont need to change your original form at all. It doesnt matter if the page is HTML or PHP both are the same (I shouldnt say that but its late and I dont care ), HTML can (if the server allows) do PHP and PHP files can output HTML. At the end of the day, HTML code is produced. To summarize, all you should have to do, is change your original forms 'action' to point to my script and change my forms 'action' to point to your mail script Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1274017 Share on other sites More sharing options...
Daryl Posted September 29, 2011 Author Share Posted September 29, 2011 Almost there ... I hope .... I did it and it did work, well, almost : I got an error message : Notice: Undefined variable: req in \\winweb\data\web01\domain\travelex\verify_details.php on line 11 Line 11 was if ($req == '1'){ It then did display : Please review and confirm your information before continuing: Order_Description: Mr Smith Amount: 4 submit: Submit (without any formatting). And just to double-check, when you say " change my forms 'action' to point to your mail script" you mean the action where you had below : ?? change the confirmed_results.php to my address? echo $text , '<form method="post" action="confirmed_results.php">' , join("\n",$new_form) , ' Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1274026 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 Oops. Add $req = '0'; to the top of my script that'll fix the error. Next, find this line $value = str_replace('\n', "$line", $value); and replace it with $value = str_replace('\n', "<br/>", $value); And the form part you just posted is correct. echo $text , '<form method="post" action="the_name_of_your_original_php_file.php">' , join("\n",$new_form) , ' Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1274031 Share on other sites More sharing options...
Daryl Posted September 29, 2011 Author Share Posted September 29, 2011 Oops. Add $req = '0'; to the top of my script that'll fix the error. ***** Yes, that fixed the error Next, find this line $value = str_replace('\n', "$line", $value); and replace it with $value = str_replace('\n', "<br/>", $value); **** I did this, but it did not add line breaks Also, the reason I asked about making a HTML form, is that your results, they do work, but they are text only, they don't look the same as my original form - if I could incorporate this php within an HTML form - is it possible ? - I could keep the "look" the same. And lastly, the results page displayed the correct results, but also added at the end : submit: Submit --- possible to eliminate this? Thanks - I know you already spent time ... I realllly appareciate :-) Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1274037 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 To remove the submit value: on the pages that produce handle the form add unset($_POST['submit']); just before the foreach ($_POST as $key => $value) { line As for the line break I see the issue.. find $conc = "{$key}:$space{$value}$line"; and replace with $conc = "{$key}:$space{$value}<br/>"; And the layout, you want the "preview" of the form, to look like the form they just came from? Might be a little confusing. Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1274044 Share on other sites More sharing options...
Daryl Posted September 29, 2011 Author Share Posted September 29, 2011 Thanks, those small fixes worked fine. Re the preview of the form in verify_details.php - I meant, that I would like to have control on how it looks - does not have to look same, but still in smae "design" as the original form. I guess formatting php is another story ..... thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1274046 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 Ok.. Well, here is where the code writes the output.. You can wrap it up however you want it.. $conc = "<div id="field"><strong>$key</strong>: $value</div><br/>"; $key is the name of the field and $value is what is stored in it.. As long as you wrap those values inside a double (") quoted string, you should be fine. (You can also use concatenation, but thats another story) Other example: $conc = "<span class=\"textfieldRequiredMsg\">$key</span> has a value of <strong>$value</strong>"; (double quotes inside a double quoted string must be escaped with the \ like above ) Dont forget.. You can write raw HTML above and below the opening and closing php tags (<?php ?>) Quote Link to comment https://forums.phpfreaks.com/topic/248098-form-results-to-web-page/#findComment-1274052 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.