Jump to content

Form results to web page


Daryl

Recommended Posts

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 ...  :shy:

Link to comment
Share on other sites

  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 = 'darylt@website.net';

 

// 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.'">';

?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

 

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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 ... ??

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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) , '

Link to comment
Share on other sites

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) , '

Link to comment
Share on other sites

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 :-)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ?>)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.