This post has been edited by mobius19: 07 August 2009 - 09:43 PM
values inputted on contact form is refreshedwhen error is detected by the form, the values are refreshed
Page 1 of 1
6 Replies - 614 Views - Last Post: 07 August 2009 - 11:24 PM
#1
values inputted on contact form is refreshed
Posted 07 August 2009 - 09:08 PM
I have been having trouble with the contact us form. It's good that I have modified it and success but when the error is detected the values they write on the form is erased or somewhat refreshed. How can I avoid that? It's hard if you are inquiring then one mistake then all of your message is lost.What do I need? thanks!
Replies To: values inputted on contact form is refreshed
#2
Re: values inputted on contact form is refreshed
Posted 07 August 2009 - 09:29 PM
Set the default values of the fields to be the POST values after the error is detected.
Really hard to explain without code...
Also, you should ask your question in your post - not the title of the thread.
Yours,
Shane~
Really hard to explain without code...
Also, you should ask your question in your post - not the title of the thread.
Yours,
Shane~
#3
Re: values inputted on contact form is refreshed
Posted 07 August 2009 - 09:42 PM
ShaneK, on 7 Aug, 2009 - 08:29 PM, said:
Set the default values of the fields to be the POST values after the error is detected.
Really hard to explain without code...
Also, you should ask your question in your post - not the title of the thread.
Yours,
Shane~
Really hard to explain without code...
Also, you should ask your question in your post - not the title of the thread.
Yours,
Shane~
oh sorry for the name of the post if its a Q, il revise it. here is the code:
<?
include("options.php");
$subject = "Website_Inquiry";
$today = date("F d, Y");
$name = $HTTP_POST_VARS["name"];
$lastname = $HTTP_POST_VARS["lastname"];
$telephone = $HTTP_POST_VARS["telephone"];
$email = $HTTP_POST_VARS["email"];
$check = $HTTP_POST_VARS["message"];
$message = $today."\n\nName: ".strip_tags(stripslashes($HTTP_POST_VARS["name"]))."\nLastName: ".strip_tags(stripslashes($HTTP_POST_VARS["lastname"]))."\nTelephone: ".strip_tags(stripslashes($HTTP_POST_VARS["telephone"]))."\nEmail Address: ".strip_tags(stripslashes($HTTP_POST_VARS["email"]))."\nMessage: ".strip_tags(stripslashes($HTTP_POST_VARS["message"]));
$headers = "From: ".$email."" . "\r\n" . "Reply-To: ".$email."" . "\r\n" . "X-Mailer: PHP/" . phpversion();
if(preg_match("/^[\.0-9a-z_-]{1,}@[\.0-9a-z-]{1,}\.[a-z]{1,}$/si", $email)) $valid = "1";
else $valid = "0";
if($name == "") {
header("Location: ".$form_file."?msg=1");
exit;
}
elseif($lastname_required == true && $name != "" && $lastname == "") {
header("Location: ".$form_file."?msg=9");
exit;
}
elseif($telephone_required == true && $name != "" && $telephone == "") {
header("Location: ".$form_file."?msg=2");
exit;
}
elseif($telephone_required == true && $valid == "0") {
header("Location: ".$form_file."?msg=8");
exit;
}
elseif($email_address_required == true && $name != "" && $email == "") {
header("Location: ".$form_file."?msg=3");
exit;
}
elseif($email_address_required == true && $valid == "0") {
header("Location: ".$form_file."?msg=4");
exit;
}
elseif($message_required == true && $subject != "" && $check == "") {
header("Location: ".$form_file."?msg=5");
exit;
}
elseif(strlen($message) >= $maximum_characters && $subject != "") {
header("Location: ".$form_file."?msg=6");
exit;
}
else {
mail($email_address, $subject, $message, $headers);
header("Location: ".$form_file."?msg=7");
}
?>
and the code at the top of my contact page is :
<?php
include("options.php");
if($_GET["msg"] == "1") $status = "<span style=\"background: #fff; color: #f00\">Values for the Full Name is required</span>";
elseif($_GET["msg"] == "2") $status = "<span style=\"color: #f00\">Values for the Telephone is required</span>";
elseif($_GET["msg"] == "3") $status = "<span style=\"color: #f00\">A value for the E-mail address is required</span>";
elseif($_GET["msg"] == "4") $status = "<span style=\"color: #f00\">ERROR: You must enter a <ins>valid</ins> email address eg. someone@yourdomain.com</span>";
elseif($_GET["msg"] == "5") $status = "<span style=\"color: #f00\">A value for the message is required</span>";
elseif($_GET["msg"] == "6") $status = "<span style=\"background: #fff; color: #f00\">ERROR: Your message cannot be more than ".$maximum_characters." characters</span>";
elseif($_GET["msg"] == "7") $status = "<span style=\"background: #fff; color: #0a0\">Your message has been successfully sent</span>";
elseif($_GET["msg"] == "8") $status = "<span style=\"background: #fff; color: #f00\">You have to enter number only. eg. 0-9</span>";
elseif($_GET["msg"] == "9") $status = "<span style=\"background: #fff; color: #f00\">You have to input your Last name</span>";
else $status = "<span style=\"background: #fff; color: #00f\"></span>";
?>
I didnt include the option.php.
Hope it helps to detect my error. thanks shane!
#4
Re: values inputted on contact form is refreshed
Posted 07 August 2009 - 10:11 PM
Try this... :
That way, the value in the global post array will be echoed back into the input field you want. I hope this is what you are looking for!
-Shaun
edit: You should use $_POST['variable_name'] instead of $HTTP_POST_VARS['variable_name']
<input type="text" name="example" value="<?php echo $_POST['variable_name']; ?>" />
That way, the value in the global post array will be echoed back into the input field you want. I hope this is what you are looking for!
-Shaun
edit: You should use $_POST['variable_name'] instead of $HTTP_POST_VARS['variable_name']
This post has been edited by sf0145: 07 August 2009 - 10:15 PM
#5
Re: values inputted on contact form is refreshed
Posted 07 August 2009 - 10:24 PM
sf0145, on 7 Aug, 2009 - 09:11 PM, said:
Try this... :
That way, the value in the global post array will be echoed back into the input field you want. I hope this is what you are looking for!
-Shaun
edit: You should use $_POST['variable_name'] instead of $HTTP_POST_VARS['variable_name']
<input type="text" name="example" value="<?php echo $_POST['variable_name']; ?>" />
That way, the value in the global post array will be echoed back into the input field you want. I hope this is what you are looking for!
-Shaun
edit: You should use $_POST['variable_name'] instead of $HTTP_POST_VARS['variable_name']
it is still not working, the values they input are refreshed when they get error message.
#6
Re: values inputted on contact form is refreshed
Posted 07 August 2009 - 11:01 PM
Can you post the full form and the handler with the code I showed you? It's easier to find the error with the entire script.
edit: this is what i meant to post earlier... this is a code i used in a simple contact form a while back:
edit: this is what i meant to post earlier... this is a code i used in a simple contact form a while back:
<input name="name" type="text" value="<?php if(!empty($_POST['name'])) echo $_POST['name']; ?>" />
This post has been edited by sf0145: 07 August 2009 - 11:03 PM
#7
Re: values inputted on contact form is refreshed
Posted 07 August 2009 - 11:24 PM
Also in options.php you may want to use a switch statement instead of an else if.
See: http://us2.php.net/m...ures.switch.php
See: http://us2.php.net/m...ures.switch.php
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|