Web Hosting Talk







View Full Version : PHP Form Script Help, Please.


theecho
01-10-2005, 03:32 PM
Hey guys,

I've created a php script within my form page (if you get me). It work perfect, except for one tiny thing. After 'potential clients' have filled the form in, i want them to go to a thankyou page at say www.mydoman.com/thnks.htm, how abouts would i do this?

heres my script; (i'll post what you need to save space) link to screenshot; http://81.97.142.198/test/untitled.bmp

<?$emailadres = "xxxxxxxxxxx";
if (isset($_POST)){
mail($emailadres, "hosting", "First Name: ".$_POST['firstname']."\nSurname: ".$_POST['surname']."\nCompany Name: ".$_POST['companyname']."\nAddress: ".$_POST['address']."\nTown/City: ".$_POST['city']."\nCounty: ".$_POST['county']."\nCountry: ".$_POST['country']."\nEmail Address: ".$_POST['email']."\nEmail Address2: ".$_POST['email2']."\nUsername: ".$_POST['username']."\nPassword: ".$_POST['password']."\nPassword2: ".$_POST['password2']."\nHosting Plan: ".$_POST['plan']."\nPayment Period: ".$_POST['payment']."\nPaypal Address:\n".$_POST['paypal']);
}
?>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
.style2 {font-size: 12px}
-->
</style>

<form action="joinform.php" method="post" class="style1">
<table summary="" border="0"><br>
<tr><br>

<?$emailadres = "liam.mayer@lamuk.co.uk";
if (isset($_POST)){
mail($emailadres, "hosting", "First Name: ".$_POST['firstname']."\nSurname: ".$_POST['surname']."\nCompany Name: ".$_POST['companyname']."\nAddress: ".$_POST['address']."\nTown/City: ".$_POST['city']."\nCounty: ".$_POST['county']."\nCountry: ".$_POST['country']."\nEmail Address: ".$_POST['email']."\nEmail Address2: ".$_POST['email2']."\nUsername: ".$_POST['username']."\nPassword: ".$_POST['password']."\nPassword2: ".$_POST['password2']."\nHosting Plan: ".$_POST['plan']."\nPayment Period: ".$_POST['payment']."\nPaypal Address:\n".$_POST['paypal']);
}
?>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
.style2 {font-size: 12px}
-->
</style>

<form action="joinform.php" method="post" class="style1">
<table summary="" border="0"><br>
<tr><br>

Cheers.
Echo.

nwkeeley
01-10-2005, 05:06 PM
Sounds like you could use a header like

header("Location: thankyou.php");


at the end of the joinform.php

theecho
01-10-2005, 06:06 PM
also i just found out that if i open this up in my browser my form appears half-down the page! Can help me on this!

Cheers.
(Oh i still have the ''thankyou'' page problemo as well)

absolethe
01-11-2005, 01:30 AM
I'm not an expert, but I would echo a meta redirect if the form's 'submit' was set. I do something SIMILAR with my tagboard/comment scripts... In my comment script, the submit button is named "com_submit". Then up in my header I have:

if (isset($_POST['com_submit'])){
echo("<meta http-equiv=\"refresh\" content=\"1\">");
}

You could do the same, but with a redirect.

Like I said, though, I'm not an expert...there is likely a better way to do it that's more PHP-ey...that was just the simplest solution I found.

-alb-
01-11-2005, 01:46 AM
Originally posted by nwkeeley
Sounds like you could use a header like

header("Location: thankyou.php");


at the end of the joinform.php

I think that this would work.
Have you tried it yet?

theecho
01-11-2005, 11:15 AM
Originally posted by -alb-
I think that this would work.
Have you tried it yet?

Yar i've tried the header thing, but when i try and open my form in my browser it opens the page i specify in the header thing.

????

absolethe
01-11-2005, 11:40 AM
I had this idea in my head that nothing could come before "header", even white space? ... so how can you stick it at the end of a script?

Anyway, I saw some talk in the PHP manual about this use of the header.

http://us4.php.net/manual/en/function.header.php

theecho
01-11-2005, 01:10 PM
im sticking this ''header'' thing everywhere, before the script, after it. Yet it still wont re-direct!

Anyone know how to solve the problem of the form appearing half way down the page?

-alb-
01-11-2005, 01:20 PM
Originally posted by theecho
Yar i've tried the header thing, but when i try and open my form in my browser it opens the page i specify in the header thing.

????

Didn't realize that you were displaying the form and processing it on the same page. Normally, I break this up in two pages, but that is just how I roll.

I am no PHP guru by any stretch, but I don't see why this wouldn't work either as a stand alone statement at the end of the script or in the last line of the PHP that emails the information:

if (isset($_POST)){
header("Location: thankyou.php");
}


....unless my syntax is botched.

Basically, I am going for: If information is posted, process the email and redirect to this page.

Hope this helps and I haven't confused you or got something wrong, I work with more ASP than PHP

theecho
01-11-2005, 02:10 PM
Originally posted by -alb-
Didn't realize that you were displaying the form and processing it on the same page. Normally, I break this up in two pages, but that is just how I roll.

I am no PHP guru by any stretch, but I don't see why this wouldn't work either as a stand alone statement at the end of the script or in the last line of the PHP that emails the information:

if (isset($_POST)){
header("Location: thankyou.php");
}


....unless my syntax is botched.

Basically, I am going for: If information is posted, process the email and redirect to this page.

Hope this helps and I haven't confused you or got something wrong, I work with more ASP than PHP

Yes that does work, although not how i want/need it, it always opens the thankyou.php first instead of the form, lol.

Animaze
01-14-2005, 09:11 PM
I'd say do it all in one page with an ELSE statement like this. Your basically just checking that the form has been submitted and if it has you show the Thank You message, otherwise it shows the form:

<html>

<head>
<title>Email Form</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
.style2 {font-size: 12px}
-->
</style>
</head>

<body>
<?php
// set the email recipient
$emailadres = 'you@domain.com';

// set the email subject
$subject = 'Hosting';

if (isset($_POST['submit'])) {

// email the message
mail($emailadres, $subject, "First Name: ".$_POST['firstname']."\nSurname: ".$_POST['surname']."\nCompany Name: ".$_POST['companyname']."\nAddress: ".$_POST['address']."\nTown/City: ".$_POST['city']."\nCounty: ".$_POST['county']."\nCountry: ".$_POST['country']."\nEmail Address: ".$_POST['email']."\nEmail Address2: ".$_POST['email2']."\nUsername: ".$_POST['username']."\nPassword: ".$_POST['password']."\nPassword2: ".$_POST['password2']."\nHosting Plan: ".$_POST['plan']."\nPayment Period: ".$_POST['payment']."\nPaypal Address:\n".$_POST['paypal']);

// if the form has been posted then display the Thank You message below:
?>

<div align="center">
<p>
Thank You. Your submission has been recieved.
</p>
</div>

<?php
} else {
// if form hasn't been posted then display the form below:
?>

<!-- BEGIN form -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="style1">
<p>
First Name: <input type="text" name="firstname" size="20" maxlength="30">
</p>

<p>
Surname: <input type="text" name="surname" size="20" maxlength="30">
</p>

<p>
Company Name: <input type="text" name="companyname" size="20" maxlength="30">
</p>

<p>
<input type="submit" name="submit" value="Send">
</p>
</form>
<!-- END form -->

<?php
// close ELSE statement
}
?>

</body>
</html>

I didn't have the HTML for your form so I just put the first few fields in there.