values inputted on contact form is refreshed

when error is detected by the form, the values are refreshed

Page 1 of 1

6 Replies - 753 Views - Last Post: 07 August 2009 - 11:24 PM Rate Topic: -----

#1 mobius19  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 26-November 08

values inputted on contact form is refreshed

Post icon  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!

This post has been edited by mobius19: 07 August 2009 - 09:43 PM

Is This A Good Question/Topic? 0
  • +

Replies To: values inputted on contact form is refreshed

#2 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 240
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

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~
Was This Post Helpful? 0
  • +
  • -

#3 mobius19  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 26-November 08

Re: values inputted on contact form is refreshed

Posted 07 August 2009 - 09:42 PM

View PostShaneK, 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~

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!
Was This Post Helpful? 0
  • +
  • -

#4 sf0145  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-June 09

Re: values inputted on contact form is refreshed

Posted 07 August 2009 - 10:11 PM

Try this... :

<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

Was This Post Helpful? 0
  • +
  • -

#5 mobius19  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 26-November 08

Re: values inputted on contact form is refreshed

Posted 07 August 2009 - 10:24 PM

View Postsf0145, on 7 Aug, 2009 - 09:11 PM, said:

Try this... :

<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. :( They may get pissed inputting all information again and again if this continues to happen. :(
Was This Post Helpful? 0
  • +
  • -

#6 sf0145  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-June 09

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:

<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

Was This Post Helpful? 0
  • +
  • -

#7 sf0145  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-June 09

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1