Page 1 of 1

I want the info that they enter to remain in the textbox

Posted: Mon Mar 21, 2011 1:41 pm
by mguise
Hi all.

I'm new to the PHP world so please forgive.

I have a php page with a ReCaptcha. http://www.rnlservicesllc.com/contact_us.php

When the user fills out the fields and incorrectly enters the info for the ReCaptcha it directs them to the following php page. http://www.rnlservicesllc.com/verify.php

Lame, I want everything to remain the same meaning all the same info the user entered remains in the fields. I want the page to say "The reCAPTCHA wasn't entered correctly. Please try again".

Hope this makes sense to you developers out there. Thanks in advance for your help.

Re: I want the info that they enter to remain in the textbox

Posted: Mon Mar 21, 2011 1:49 pm
by Jonah Bron
In order to do that, set the action of the form to the same page, so that it submits to itself. Then put your submission code into that page.

Re: I want the info that they enter to remain in the textbox

Posted: Mon Mar 21, 2011 1:55 pm
by fugix
and make sure not to set a refresh header on that page or you will lose the info in the textbox

Re: I want the info that they enter to remain in the textbox

Posted: Tue Mar 22, 2011 4:08 pm
by mguise
In theory I see what we are trying to do. In practice I'm running into a learning curve wall.

Do you mind taking at look at the code? The page is failing I am not sure why I can't see it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="RNL Services LLC installs Fire Protection Systems that are cost-effective, dependable and proven to protect your valued property from the dangers of fire. Whether you require a new Fire Protection System or need someone to inspect or service an installed Fire Protection System you can depend on RNL Services LLC. " />
<link rel="shortcut icon" href="images/favicon.jpg">
<meta property="og:title" content="RNL Services LLC" />
<meta property="og:description" content="RNL Services LLC installs Fire Protection Systems that are cost-effective, dependable and proven to protect your valued property from the dangers of fire." />
<meta property="og:image" content="http://www.rnlservicesllc.com/images/rnllogo.jpg" />
<title>RNL Services LLC Contact Us</title>
<style type="text/css">
<!--
body {
background-color: #c02327;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
color: #000;
background-image: url('images/rnl_services_contact.jpg');
background-repeat: no-repeat;
background-attachment:fixed;
background-position: top center;
}
-->
</style>
<link href="rllstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">

function getKey(e) {
var kC = e.keyCode ? e.keyCode : e.which ? e.which : null;
if (kC && (kC == 37 || kC == 39)) return false; //arrow keys
}

function formatPhone(e, field) {
var kC = e.keyCode ? e.keyCode : e.which ? e.which : null;
if (kC) {
if (kC == 8) return true; //backspace
var keyChar = String.fromCharCode(kC);
if (!/\d/.test(keyChar)) return false; //numbers only
if (field.value.length == 0 && keyChar == '0') //no area codes begin with zero
return false;
if (field.value.length == 3) field.value += '-';
if (field.value.length == 7) field.value += '-';
}
return true;
}

</script>
</head>

<body onload="document.form1.name.focus()">
<div id="page_home">
<div id="contacta">
<div id="blue"><a href="index.html" target="_self"><img src="images/clickit.jpg" alt="RNL Services LLC" width="231" height="182" border="0" /></a></div>
<div id="contact_usa"><a href="index.html" target="_self">HOME</a> | <a href="services.html" target="_self">SERVICES</a> | <a href="installation.html" target="_self">INSTALLATION</a> | <span id="grey">CONTACT US</span></div>
</div>
<div id="contactb">
<form method="post" action="$_SERVER['PHP_SELF'] name="form1" id="form1">
<div id="contact_us_nowa">
<div id="contactusa">First Name:</div>
<div id="contactusb">Last Name:</div>
<div id="contactusc">Email:</div>
<div id="contactusd">Telephone Number:</div>
</div>
<div id="contact_us_nowb">
<div id="contactusnowa"><input name="name" type="text" id="name" tabindex="1" size="25"/></div>
<div id="contactusnowb"><input name="last" type="text" id="last" tabindex="2" size="25"/> </div>
<div id="contactusnowc"><input name="email" type="text" id="lastemail" tabindex="3" size="25"/> </div>
<div id="contactusnowd"><input name="phone" type="text" id="phone" tabindex="5" onkeypress="return formatPhone(event,this)" onkeydown="return getKey(event,this)" size="12" maxlength="12"/> </div>
<div id="contactusnowe">ex. #########</div>
</div>
<div id="contact_us_nowc">How can we help you?</div>
<div id="contact_us_nowd">
<div id="conta"><textarea name="help" id="help" cols="60" rows="10" tabindex="6"></textarea>
</div>
<div id="contb">
<?php
require_once('recaptchalib.php');
$publickey = "6LcgXcISAAAAAAyQgjchXTWy8lyC_8gexpGadSHB"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
</div>
</div>
<div id="contact_us_nowe">
<div id="contusa">Daytime:</div>
<div id="contusb"><input type="radio" name="when" value="Daytime" id="when_0" tabindex="7"/></div>
<div id="contusc">Evening:</div>
<div id="contusd"><input type="radio" name="when" value="Evening" id="when_1" tabindex="8"/></div>
<div id="contuse"><input type="submit" name="Submit" value="Submit" tabindex="9" />
</div>
<div id="contusf"><input type="reset" name="reset" id="reset" value="Reset" tabindex="10"/>
</div>
</div>
</form>
</div>
<div id="contactc">© 2011 RNLServicesLLC.com All Rights Reserved. Site created by <a href="http://www.mattguise.com/" target="_blank">MattGuise.com</a></div>
</div>
</body>
</html>


<?php

require_once('recaptchalib.php');
$privatekey = "6LcgXcISAAAAAM1AVPk9klR9olDeHbtseB2vt3DP";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
$theResults = <<<EOD

//Not sure what to put here??????


echo "$theResults";

} else {



/* Email Variables */



$emailSubject = 'Contact Form';



$webMaster = 'mguise@mattguise.com';

// $webMaster = 'lvennard@yahoo.com';

//$webMaster = 'murrterr@rcn.com';



/* Data Variables */


$name = $_POST['name'];

$last = $_POST['last'];

$email = $_POST['email'];

$phone = $_POST['phone'];

$help = $_POST['help'];

if (isset($_POST["submit"])) {
echo $_POST["when"];
}



$body = <<<EOD

\r\n \r\n <br>

First Name: $name \r\n <br>

Last Name: $last \r\n <br>

Email: $email \r\n <br>

Phone: $phone \r\n <br>

How can we help you?: $help \r\n <br>

When: $when \r\n <br>

EOD;





$from = "From: Rusty@RNLServicesLLC.com\r\n";

$from .= "Reply-To: ".$email."\r\n";

$from .= "Content-type: text/html\r\n";



mail($webMaster, $emailSubject, $body, $from);




/* Results rendered as HTML */



$theResults = <<<EOD


<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="RNL Services LLC installs Fire Protection Systems that are cost-effective, dependable and proven to protect your valued property from the dangers of fire. Whether you require a new Fire Protection System or need someone to inspect or service an installed Fire Protection System you can depend on RNL Services LLC. " />
<link rel="shortcut icon" href="images/favicon.jpg">
<meta property="og:title" content="RNL Services LLC" />
<meta property="og:description" content="RNL Services LLC installs Fire Protection Systems that are cost-effective, dependable and proven to protect your valued property from the dangers of fire." />
<meta property="og:image" content="http://www.rnlservicesllc.com/images/rnllogo.jpg" />
<title>RNL Services LLC Contact Us</title>
<style type="text/css">
<!--
body {
background-color: #c02327;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
color: #000;
background-image: url('images/rnl_services_contact.jpg');
background-repeat: no-repeat;
background-attachment:fixed;
background-position: top center;
}
-->
</style>
<link href="rllstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">

function getKey(e) {
var kC = e.keyCode ? e.keyCode : e.which ? e.which : null;
if (kC && (kC == 37 || kC == 39)) return false; //arrow keys
}

function formatPhone(e, field) {
var kC = e.keyCode ? e.keyCode : e.which ? e.which : null;
if (kC) {
if (kC == 8) return true; //backspace
var keyChar = String.fromCharCode(kC);
if (!/\d/.test(keyChar)) return false; //numbers only
if (field.value.length == 0 && keyChar == '0') //no area codes begin with zero
return false;
if (field.value.length == 3) field.value += '-';
if (field.value.length == 7) field.value += '-';
}
return true;
}

</script>
</head>

<body onload="document.form1.name.focus()">
<div id="page_home">
<div id="contacta">
<div id="blue"><a href="index.html" target="_self"><img src="images/clickit.jpg" alt="RNL Services LLC" width="231" height="182" border="0" /></a></div>
<div id="contact_usa"><a href="index.html" target="_self">HOME</a> | <a href="services.html" target="_self">SERVICES</a> | <a href="installation.html" target="_self">INSTALLATION</a> | <a href="contact_us.php" target="_self">CONTACT US</a></div>
</div>
<div id="contactb">
<form action="verify.php" method="post" name="form1" id="form1">
<div id="contact_us_nowa"></div>
<div id="contact_us_nowb"></div>
<div id="contact_us_nowc"></div>
<div id="contact_us_nowd">Thank you, RNL SERVICES LLC. will contact you soon.</div>
<div id="contact_us_nowe"></div>
</form>
</div>
<div id="contactc">© 2011 RNLServicesLLC.com All Rights Reserved. Site created by <a href="http://www.mattguise.com/" target="_blank">MattGuise.com</a></div>
</div>
</body>
</html>







EOD;

echo "$theResults";


}
?>

Re: I want the info that they enter to remain in the textbox

Posted: Tue Mar 22, 2011 9:10 pm
by Jonah Bron
Define "failing". Do you get an error?

Re: I want the info that they enter to remain in the textbox

Posted: Tue Mar 22, 2011 10:37 pm
by miramichiphoto
I use a query to populate a form, set the fields I dont't want edited to "hidden" or READONLY. When the form gets submitted (the form action is the same page), it reloads with the new values in the form fields. I think this is what you are trying to do. Here is some sample code:

Code: Select all

<?php	// START FORM PROCESSING	
	
if (isset($_POST['submit'])) { // Form has been submitted improperly.

		$display_name = trim($_POST['display_name']);
		$admin = trim($_POST['admin']);
		$phone1 = trim($_POST['phone1']);
		$phone2 = trim($_POST['phone2']);
		$email = trim($_POST['email']);
		
		$query = "UPDATE `users` SET `phone1`='".$phone1."',`phone2`='".$phone2."',`email`='".$email."' WHERE `display_name`='".$_SESSION['display_name']."'";
	        mysql_query($query, $connection) or die(mysql_error());
	        $message = 'Your profile was edited successfully' ;
			
			
}
?>

    
       <?php  // beginning of query generated table with a form on each row.
	   
	 
	   echo "<table border='1' cellpadding='4px'  style='border-color:#FFF'>";
	   
	   
		$query = "SELECT * FROM users WHERE `display_name`='".$_SESSION['display_name']."'";
		$result = mysql_query($query, $connection);
		$num=mysql_numrows($result);
		$i=0;
		
		while ($i < $num){
		

$row = mysql_fetch_array($result);

echo '<form action="coach_edit_profile.php" method="post"><tr>';
echo '<td><input type="text" READONLY name="display_name"  value="'.$row['display_name'].'" /></td>';
echo '<td> '.$ref.'</td>';
echo '<td> <input type="text" name="phone1"  value="'.$row['phone1'].'" /></td>';
echo '<td> <input type="text" name="phone2"  value="'.$row['phone2'].'" /></td>';
echo '<td> <input type="text" name="email"  value="'.$row['email'].'" /></td>';
echo '<td><input type="submit" name="submit" value="Edit User" /></td></tr></form>';
$i++;
		}
 
  
  echo "</table>"

?>