PDA

For continued disscussion on this topic : Form filling, confirming and sending it via email



George W. Bush
06-15-2001, 04:37 AM
I am testing a form (called "one.php") with 4 fields (login, password, fullname, url) when the submit button is clicked it goes to "two.php"

On page "two.php" I would like to print again the values of the variables that it obtained from "one.php" to confirm, and have a button that when clicked the results of the variables to be send to an email, and if not they can click the "Return Back" button that will take them back to and make changes.

I have the following, but it just does not work with the "two.php" - it does not like that if statement I think. I will keep making changes to this, and hope to make it work. If you have any ideas I would appreciate them once more. Thanks!



one.php
-----------------------------------------------------------------

<HTML><BODY>

<FORM NAME="TheForm" METHOD="post" ACTION="two.php">
...
</FORM>

</BODY></HTML>




two.php
-----------------------------------------------------------------

<?

if ($submit == "click")
{
mail("tester@hotmail.com", "Form Testing", "$login<BR>$password<BR>$fullname<BR>$url");
PRINT "Thank you, your message was sent";
}

echo '
<html><body>
<FORM METHOD="POST" "<? echo $PHP_SELF; ?>">
<TR><TD>
<?
PRINT "Greetings $login, thank you for filling the form<BR>";
PRINT "Your password is $password!<BR>";
PRINT "The fullname is $fullname..<BR>";
PRINT "The URL is: $url<BR>";
?>
<input type="submit" name="submit" value="click">
<input type="submit" value ="Go Back">
</FORM>
</body></html>
';
?>

George W. Bush
06-15-2001, 05:33 AM
Okay... this is something cool cooking here... this is a working script. Also, thanks to jonsteele for assistance on writting the form content to a text file...

This will write to a text file, send you an email!! I still would like to incorporate into this one, or the one above (or both) an option where one will have a confirmation written to the page indicating the person what he/she has inputed in the fields, if the info is correct then click on another button to continue (to send email and write it to the text file!)

Quite niffty I must say... :)



<?
$file_name = "result.txt";
?>

<?php

if ($submit == "click"){
{
$mailTo = "youremail@supermonkeyboy.com";
$msgSubject = "Downloading MediaKit";
$msgBody = "$login, $password, $fullname, $url";
mail ($mailTo, $msgSubject, $msgBody);
}

// check existence of file (or try to create it)
// a better alternative to touch() would be is_file, is_writable and so on.
$try = touch($file_name);
if (!$try) {
echo "<p>Sorry I can't open a file, something is wrong";
exit;
}

// so we can make a big string with tabs between the elements
// note that we add a \n (line break) to the end of the string.
$output_line = "LOGIN:\t$login\nPASSWORD:\t$password\nFULLNAME:\t$fullname\nURL:\t$url\n\n";

// Now open the file (get a file pointer)
// We will append to it and therefore use the "a" option
$output_stream = fopen($file_name, "a");

// and dump the string into the file
$result = fputs ($output_stream, $output_line);

// close the file pointer
fclose($output_stream);


PRINT "Thank you $name very much.\nYour form was send via email to us, and written to a text file for record keeping.\nPlease buzz off now.\nThank you!";
}

else{
echo '
<html><body>

<FORM METHOD="POST" "<? echo $PHP_SELF; ?>">

Login
<input type="text" name="login"><br>
Password
<input type="text" name="password"><br>
Fullname
<input type="text" name="fullname"><br>
URL
<input type="text" name="url"><br>
<input type="submit" name="submit" value="click">

';
}

?>
</body></html>

lorddog
06-15-2001, 12:49 PM
just to let you know, this may be the error you had at first?

if you submit a form with javascript this.form.submit();
it will NOT submit the submit button name:value pair.
and you ARE checking the submit button. Another error
MAY be that you can't name the submit button name="submit"
as it is a keyword.

lastly in the second reply you made I don't see any ending form tags and open tags like that can be bad in Netscape.

Lorddog

George W. Bush
06-15-2001, 02:06 PM
The two scripts are different, yet they should perform the same thing. I just cannot get it to display the results on a page before another button is clicked to submit and send it. Still trying to figure this one out...

And yes, the </FORM> should be closed.

lorddog
06-16-2001, 03:06 AM
to have a middle page that displays the info with a confirmation submit button you can
make the middle page recieve the form data and put it all into
hidden form values and print it out.
Then with THAT submit button go to the final page that sends it.

Lorddog