Hi All,

I dont ve any clue on how to perform th efeat which i am going to describe below .....

i ve a contact form with an image verification before submitting the data to db ... its working fine ....

the problem is when the user makes a mistake in image verification text .... the form data is lost ....

what i want to do is that only image refreshes but the data remains there in the form ... otherwise the user can be annoyed ...

please help me out ....

Thanks a million in advance

<input type='text' name='name' value=<?php echo $_REQUEST['name']; ?>>

When the submit button is pressed and if the captcha is wrong, it will still show the posted values.

<?php
/* form processing, captcha generate etc */ 
?>
<form action='<?php echo $_server['php_self']; ?>' method='post'><br>
bog: <input type='text' name='bog' value="<?php if(isset($_post['bog'] { echo $_post['bog']; } ?>"><br>
big: <input type='text' name='big' value="<?php if(isset($_post['big'] { echo $_post['big']; } ?>"><br>
<input type='text' name='captcha'><br>
<input type='submit' onclick='return(confirm("Are you sure?"));' value='Submit'>
</form>
<?php
/* form processing, captcha generate etc */ 
?>
<form action='<?php echo $_server['php_self']; ?>' method='post'><br>
bog: <input type='text' name='bog' value="<?php if(isset($_post['bog'] { echo $_post['bog']; } ?>"><br>
big: <input type='text' name='big' value="<?php if(isset($_post['big'] { echo $_post['big']; } ?>"><br>
<input type='text' name='captcha'><br>
<input type='submit' onclick='return(confirm("Are you sure?"));' value='Submit'>
</form>

To almostbob...
Two closing RIGHT PARENTHESIS are missing in your code

<?php if(isset($_post['bog'])) { echo $_post['bog']; } ?>
<?php if(isset($_post['big'])) { echo $_post['big']; } ?>

I believe that the $_post should be $_POST

I believe that the $_post should be $_POST

yes. and echoing data directly from the $_POST array is a huge security risk. You need to sanitize it before you echo it to the browser.

i use sessions to retain data.

Thanks a lot to everybody for replying ..... but i was not able to explain my problem i think ..... i mean the main problem is in my coding i guess ...

i am sending the form variables through post to another page where first of all the image verification code is being matched .... if it matches well the data goes to the database and user is sent to the home page using header ....

if the code is wrong its sent back to the form page again using header .... and thats why i loosing all the values no matter what method i use to get the values back ....

here's my original code .... for the two pages ....

please help me out .. and forgive me for not explaining everything in the beginning .....

code for the contact form page contact.php ::

<?php session_start();  ?>
 <form action="submitcontact.php" method="POST" id="contactrequest" name="contactrequest">
            <table align="center" class="contactinfo" id="contactinfo" style="background:url(images/contact.jpg) center no-repeat;">
			<tbody>
                            <tr>
                <td align="right"><label for="name">* Your Name:</label></td>
                <td>&nbsp;&nbsp;</td>
                <td align="left"><input type="text" class="textInput" id="name" name="name" value="" /></td>
              </tr>
               <tr>
                <td align="right"><label for="email">* Your Email:</label></td>
                <td>&nbsp;&nbsp;</td>
                <td align="left"><input type="text" class="textInput" id="email" name="email" /></td>
              </tr>
              <tr>
                <td align="right"><label for="phone">* Bussiness Phone Number:</label></td>
                <td>&nbsp;&nbsp;</td>
                <td align="left"><input type="text" class="textInput" id="phone" name="phone" onkeyup="this.value=this.value.replace(/[' ']/g,'')" /></td>
              </tr>
              <tr>
                <td align="right"><label for="company">Company Name:</label></td>
                <td>&nbsp;&nbsp;</td>
                <td align="left"><input type="text" class="textInput" name="company" id="company"/></td>
              </tr>
              <tr>
                <td align="right" valign="middle"><label for="add_info">If in a few words, please explain what we can help you with:</label></td>
                <td>&nbsp;&nbsp;</td>
                <td align="left"><textarea rows="7" cols="15" class="textInput" id="add_info" name="add_info" ></textarea></td>
              </tr>
	       <tr>
                <td align="right" valign="top">Enter Code : <img src="imgverify.php" align="middle"></td>
                <td>&nbsp;&nbsp;</td>
                <td align="left"><input type="text" name="number" class="textInput" id="number"/></td>
              </tr>
               <tr>
                <td colspan="3" align="center"><a href="#" onClick="submitbutton('save')" alt="Submit Contact Request"> <img src="images/submit_form.png" border="0" /></a></td>
              </tr>
            </tbody></table>
    </form>
<?php 
$val = $_SESSION['formsubmit'];
if($val == 'false'){
echo "<script>alert('Verification Code did not match, Please Try Again!')</script>"; 
}
session_destroy();
?>

code for submitcontact.php :::

<?php 
session_start(); 
$number = $_POST['number'];
// the value for $_SESSION['image_value'] is coming from a //separate php file responsible for generating ver' image
if(md5($number) != $_SESSION['image_value'])
{ 
    $_SESSION['formsubmit'] = "false";
	header("Location: contact.php");
} 
else
{
//this will trigger an alert box at the index.php page that the contact info has been submitted .
 $_SESSION['formsubmit'] = "true";
 
require("classes/mysql_class.php");
	try{
	
	$name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $company = $_POST['company'];
    $add_info = $_POST['add_info'];
	$req_date = date("D M j G:i:s Y");
			  
$m=new MySQLDB("db");
		
$qryArray=array("cid" =>'NULL',
				"name"=>"$name",
				"email"=>"$email",
				"phone"=>"$phone",
				"company"=>"$company",
				"add_info"=>"$add_info",
				"req_date"=>"$req_date",
				);
		
		$m->insertRow($qryArray,"contactinfo");
		
			
header("Location: index.php");	
	
}catch (Exception  $e) {      // Will be caught
		echo "Caught my exception\n", $e->getMessage();
	}
}
?>

If you want to send the variables back to the first page then you can store them as session variables in the second module or you can include them in a form on the second page as hidden variables.
In the first module, every form variable would need a name and a value as:

"<input type="text" class="textInput" id="email" name="email" value=\"$email\"  /></td>

Thus the code at line 5 in the second module:

if(md5($number) != $_SESSION['image_value'])
{     
$_SESSION['formsubmit'] = "false";	
header("Location: contact.php");
}

would become:

if(md5($number) != $_SESSION['image_value'])
{   
$_SESSION['form_email'] = $email;
...
$_SESSION['formsubmit'] = "false";	
header("Location: contact.php");
}

If you take this approach, then you need to set all the form values in the first module (from the session variables) before you start the form.

-OR-
For the hidden variable approach:

if(md5($number) != $_SESSION['image_value'])
{   
echo "<br>You have an error in your input, click the button to return to the form to correct your input";  

echo "
<form action=contact.php method=post>
<input type=hidden name=email value=$email>
...
<input type=submit name=Correct>
</form>
";
...

Chris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.