hakmir Posted October 26, 2008 Share Posted October 26, 2008 Hi everybody, I have submitform.php with captcha. It works fine but when the person who is filling the form enters wrong code in captcha are the webpage tells him that code was incorrect so go back to form page. But when he goes back all the things he filled are gone. How can I fix this problem. At least for "yourrecipe" area. Here is the code <?php /** * Project: Securimage: A PHP class for creating and managing form CAPTCHA images<br /> * File: form.php<br /><br /> * * This is a very simple form sending a username and password.<br /> * It demonstrates how you can integrate the image script into your code.<br /> * By creating a new instance of the class and passing the user entered code as the only parameter, you can then immediately call $obj->checkCode() which will return true if the code is correct, or false otherwise.<br /> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version.<br /><br /> * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details.<br /><br /> * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br /><br /> * * Any modifications to the library should be indicated clearly in the source code * to inform users that the changes are not a part of the original software.<br /><br /> * * If you found this script useful, please take a quick moment to rate it.<br /> * http://www.hotscripts.com/rate/49400.html Thanks. * * @link http://www.phpcaptcha.org Securimage PHP CAPTCHA * @link http://www.phpcaptcha.org/latest.zip Download Latest Version * @link http://www.phpcaptcha.org/Securimage_Docs/ Online Documentation * @copyright 2007 Drew Phillips * @author drew010 <[email protected]> * @version 1.0.3.1 (March 23, 2008) * @package Securimage * */ session_start(); ?> <html> <head> <title>Submit recipe form</title> </head> <body> <?php $dbcnx = @mysql_connect('localhost', 'root', ''); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('recipetime')) { exit('<p>Unable to locate the experience ' . 'database at this time.</p>'); } ?> <?php if (empty($_POST)) { ?> <form id="form1" name="form1" method="post" action="submitrecipe.php"> <label><strong>SUBMIT YOUR RECIPE</strong><br /> <br /> Name<br /> <input type="text" name="yourname" id="yourname" /> </label> <p>Country<br /> <label> <select name="yourcountry" id="yourcountry"> <option>USA</option> <option>CANADA</option> <option>ENGLAND</option> </select> </label> </p> <p>Type of Food <br /> <label> <select name="typeoffood" id="typeoffood"> <option>DESERT</option> <option>ENTREE</option> <option>SPICY</option> </select> </label> </p> <p>Your recipe<br /> <label> <textarea name="yourrecipe" id="yourrecipe" cols="45" rows="5"></textarea> </label> </p> <p> <label> <!-- pass a session id to the query string of the script to prevent ie caching --> <img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br /> <input type="text" name="code" /><br /> <input type="submit" value="Submit Form" /> </form> <?php } else { //form is posted include("securimage.php"); $img = new Securimage(); $valid = $img->check($_POST['code']); if($valid == true) { echo "<center>Thanks, you entered the correct code.</center>"; } else { echo "<center>Sorry, the code you entered was invalid. <a href=\"javascript:history.go(-1)\">Go back</a> to try again.</center>"; } } ?> <?php if (isset($_POST['yourrecipe'])&&($valid==true)): // A new recipe has been entered // using the form. $yourname = $_POST['yourname']; $yourcountry = $_POST['yourcountry']; $typeoffood = $_POST['typeoffood']; $yourrecipe = $_POST['yourrecipe']; $sql = "INSERT INTO recipeform SET name='$yourname', country='$yourcountry', typeoffood = '$typeoffood', yourrecipe='$yourrecipe'"; if (@mysql_query($sql)) { echo '<p>New recipe added</p>'; echo "<a href=\"searchrecipe.php\">Search Recipe</a></center>"; } else { exit('<p>Error adding new recipe: ' . mysql_error() . '</p>'); } ?> <?php endif; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/130129-go-back-button-and-form-values-are-gone-with-captcha/ Share on other sites More sharing options...
ratcateme Posted October 26, 2008 Share Posted October 26, 2008 they way i do it is i store all the info the user inputs in a a session var and when i display the form i check to see if the sessions values for the form i am displaying are set if so then i output it. Scott. Link to comment https://forums.phpfreaks.com/topic/130129-go-back-button-and-form-values-are-gone-with-captcha/#findComment-674773 Share on other sites More sharing options...
PFMaBiSmAd Posted October 26, 2008 Share Posted October 26, 2008 Each type of form field has a method of outputting a value or content. You would need to add php code to echo what has already been entered - http://w3schools.com/tags/tag_input.asp (the value="..." parameter.) http://w3schools.com/tags/tag_textarea.asp (content between the <textarea></textarea> tags.) http://w3schools.com/tags/tag_option.asp (the selected="selected" parameter.) Link to comment https://forums.phpfreaks.com/topic/130129-go-back-button-and-form-values-are-gone-with-captcha/#findComment-674774 Share on other sites More sharing options...
hakmir Posted October 26, 2008 Author Share Posted October 26, 2008 THanks for the advice guys. I appreciate it. But I am new to programming. I guess I will have to try what I know already. Link to comment https://forums.phpfreaks.com/topic/130129-go-back-button-and-form-values-are-gone-with-captcha/#findComment-674777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.