Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Post Submit - Blank page 1

Status
Not open for further replies.

craigglenn

Technical User
Oct 30, 2003
42
0
0
US
I have searched high and low and can't seem to find the solution that fits my situation.

Wordpress 3.X
PHP 5.x
MySql 5.0
URL with Post Form:
Problem: The form works, the PHP loads data into my table, the email fires (still working on some formatting issues with that) but after hitting submit it goes to a blank page and does not return to the original page. Even though everything worked. HTML and PHP below. Thanks in advance for your help.


Form html

<form action="/insert_contact.php" method="post">
<table border="0" width="100%">
<tbody>
<tr>
<td>Name:</td>
</tr>
<tr>
<td><input id="name" name="name" type="text" /></td>
</tr>
<tr>
<td>Email Address:</td>
</tr>
<tr>
<td><input id="email" name="email" type="text" /></td>
</tr>
<tr>
<td>Comment:</td>
</tr>
<tr>
<td><textarea name="comment" rows="5" cols="60"></textarea></td>
</tr>
<tr>
<td><input id="Submit!" name="Submit!" type="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>

PHP

<?php
$con = mysql_connect('hir1028411423720.db.6837474.hostedresource.com','UserName','Password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('hir1028411423720', $con);

$_name = mysql_real_escape_string($_POST["name"]);
$_email = mysql_real_escape_string($_POST["email"]);
$_comment = mysql_real_escape_string($_POST["comment"]);
$regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";
$sql = "INSERT INTO wp_contact (name, email, comment)
VALUES ('$_name','$_email','$_comment')";

if ($_email==NULL)
{
die('Email is Required: Click the back button on your browser to return and try again.' . mysql_error());
}
if (preg_match($regexp, $_email))
{
mysql_query($sql, $con);
}
else
{
die('Invalid Email Address! Please enter a valid email address. Click the back button on your browser to return' . mysql_error());
}
mysql_close($con);

$to = "craig.glenn@yahoo.com";
$subject = "New Comment on HireMaureen.com";
$message = $_comment;
$from = $_email;
$headers = "From: $_name" . "\r\n" . "Email: $_email";
mail($to,$subject,$message,$headers);

exit;

?>

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
Why would it? There's nothing in your code telling it it should return to the contact page. It simply submits the form to the PHP script to process and that's it.

Provided you have no output whatsoever prior to the end of the script, you could issue a header command to send the user to another page.

Code:
header("Location: [URL unfurl="true"]http://www.example.com/");[/URL]

Other than that, you could use a meta tag to redirect, or even a Javascript function once everything is done.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Vacunita,

Well First I am new to PHP so forgive my ignorance. I did spend hours today trying to find the solution and figure it out on my own.

Header did work for me but I had to take a stab at where to include it since you didn't say.

Thank you for responding and helping me solve this issue.

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
Sorry if I came off a little rude. And yes the header call should be placed at the end of your code so it redirects after everything is done.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks, I really do appreciate your help, it's been a long one.

Worked like a charm and that's a lesson I wont have to learn again.

Now off to tackle the email issues... Learning is fun... lol


Craig

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top