Jump to content

[SOLVED] Help Please


HNX

Recommended Posts

ok theres oi problem with my contact us form

 

here is the link to it: http://www.phpfreaks.com/forums/index.php/topic,171104.0.html

 

what i want to do is that instead of it going to a blank page after i fill all the information and press submit but instead i want it to just load in the web page and tell me the same message :

"your message has been received"

 

thanks,

HNX

Link to comment
Share on other sites

Try This:

 

<?php

$msg="Please Fill In Form Fields Below"; // Initialize Variable

if(isset($_POST["Submit"])) {

$name = stripslashes($_POST['$name']);
$email = stripslashes($_POST['$email']);
$subject = stripslashes($_POST['$subject']);
$text = stripslashes($_POST['$text']);

// simple validation
if ($name == NULL)
{
$msg="Enter Your Name";
exit;
}
else if ($email == NULL) // you also may want to use a regex validation
{
$msg="Enter Valid Email Address";
exit;
}
else if ($subject == NULL) {
$msg="Enter Subject";
exit;
}
else if ($text == NULL) {
$msg="Enter Comments/Text";
exit;
}
else {
$msg="Thank you for your interest, your e-mail was sent.";
}

$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes($subject);
$text = stripslashes($text);
mail(' myemail@hotmail.com',$subject,$text,"From: $name <$email>");
echo "$msg<br><br>\n";
}
?>

<form method="post" name="form1" id="form1">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%"><span class="style108">Subject</span></td>
<td width="2%"><span class="style104">:</span></td>
<td width="82%"><input name="subject" type="text" id="subject" size="50" /></td>
</tr>
<tr>
<td><span class="style108">Message</span></td>
<td><span class="style104">:</span></td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td><span class="style108">Name</span></td>
<td><span class="style104">:</span></td>
<td><input name="name" type="text" id="name" size="50" /></td>
</tr>
<tr>
<td><span class="style108">Email</span></td>
<td><span class="style104">:</span></td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</form>

 

PS: You really should not double post.

Link to comment
Share on other sites

I did not test my first code - it was flawed - try this out instead - I think it will do the trick for you:

 

<?php

@$subject = stripslashes($_POST['subject']);
@$detail = stripslashes($_POST['detail']);
@$name = stripslashes($_POST['name']);
@$customer_mail = stripslashes($_POST['customer_mail']);

function theForm()
{
echo '<form method="post" name="form1" id="form1">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%"><span class="style108">Subject</span></td>
<td width="2%"><span class="style104">:</span></td>
<td width="82%"><input name="subject" type="text" id="subject" size="50" value="'. $_POST['subject'] .'" /></td>
</tr>
<tr>
<td><span class="style108">Message</span></td>
<td><span class="style104">:</span></td>
<td><textarea name="detail" cols="50" rows="4" id="detail">'. $_POST['detail'] .'</textarea></td>
</tr>
<tr>
<td><span class="style108">Name</span></td>
<td><span class="style104">:</span></td>
<td><input name="name" type="text" id="name" size="50" value="'. $_POST['name'] .'"/></td>
</tr>
<tr>
<td><span class="style108">Email</span></td>
<td><span class="style104">:</span></td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50" value="'. $_POST['customer_mail'] .'" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="submit">
<input type="reset"></td>
</tr>
</table>
</form>';
}


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

if (strlen($subject) == 0 )
{
echo "<span style=\"color:red\">Enter Subject</span><br><br>";
theForm();
exit;
}

if (strlen($detail) == 0 )
{
echo "<span style=\"color:red\">Enter Comments/Text</span><br><br>";
theForm();
exit;
}

if (strlen($name) == 0 )
{
echo "<span style=\"color:red\">Enter Your Name</span><br><br>";
theForm();
exit;
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $customer_mail))
{
echo "<span style=\"color:red\">Enter Valid Email Address</span><br><br>";
theForm();
exit;
}

if (strlen($customer_mail) == 0 )
{
echo "<span style=\"color:red\">Enter Valid Email Address</span><br><br>";
theForm();
exit;
}

echo "<span style=\"color:red\">Email Received</span><br><br>";

$name="$name";
$email="$email";
$subject="$subject";
$text="$text";
mail('myemail@hotmail.com',$subject,$text,"From: $name <$email>");

}

?>

<form method="post" name="form1" id="form1">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%"><span class="style108">Subject</span></td>
<td width="2%"><span class="style104">:</span></td>
<td width="82%"><input name="subject" type="text" id="subject" size="50" /></td>
</tr>
<tr>
<td><span class="style108">Message</span></td>
<td><span class="style104">:</span></td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td><span class="style108">Name</span></td>
<td><span class="style104">:</span></td>
<td><input name="name" type="text" id="name" size="50" /></td>
</tr>
<tr>
<td><span class="style108">Email</span></td>
<td><span class="style104">:</span></td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="submit">
<input type="reset"></td>
</tr>
</table>
</form>

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.