joshgarrod Posted December 18, 2010 Share Posted December 18, 2010 Hi, I am searching for a basic, easy to implement php form validation script that checks if the user has filled out a field, if they havent to tell them so. i have tried basic if statements but it refreshes the page and all the other fields that were filled in are clear. Anyone know of any tricks or scripts that are good? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/222080-simple-php-from-validation/ Share on other sites More sharing options...
denno020 Posted December 18, 2010 Share Posted December 18, 2010 You want to add a simple javascript function to your page. This will allow you to check the fields without refreshing the page. If you want to use php, then the page will need to be refreshed each time, as the php get's executed back at the server, not up where the client is. If you want an example of some javascript code, let me know. Otherwise just google it . Denno Quote Link to comment https://forums.phpfreaks.com/topic/222080-simple-php-from-validation/#findComment-1149073 Share on other sites More sharing options...
BlueSkyIS Posted December 18, 2010 Share Posted December 18, 2010 regardless of what kind of javascript checks you have, you must also validate the data on the server. 1. Always use server-side data validation. 2. If you have the time or desire, add client-side (Javascript) checks. Quote Link to comment https://forums.phpfreaks.com/topic/222080-simple-php-from-validation/#findComment-1149075 Share on other sites More sharing options...
denno020 Posted December 18, 2010 Share Posted December 18, 2010 I was merely suggesting javascript to check if the field has been filled in, as the original question asked. Validating if the entered data matches when compared to a db (or something), like for usernames or passwords, is a different matter. Denno Quote Link to comment https://forums.phpfreaks.com/topic/222080-simple-php-from-validation/#findComment-1149078 Share on other sites More sharing options...
PFMaBiSmAd Posted December 18, 2010 Share Posted December 18, 2010 The question asked for a php script - ... php form validation script ... Quote Link to comment https://forums.phpfreaks.com/topic/222080-simple-php-from-validation/#findComment-1149080 Share on other sites More sharing options...
denno020 Posted December 18, 2010 Share Posted December 18, 2010 ... that checks if the user has filled out a field, if they havent to tell them so. Nothing is said about validating the actual information in the field. Only that there is something in there. I don't want to start an argument, but from reading the original question, this it he impression that I got as to what was being asked. Denno Quote Link to comment https://forums.phpfreaks.com/topic/222080-simple-php-from-validation/#findComment-1149081 Share on other sites More sharing options...
BlueSkyIS Posted December 18, 2010 Share Posted December 18, 2010 php form validation script that checks if the user has filled out a field, if they havent to tell them so. Quote Link to comment https://forums.phpfreaks.com/topic/222080-simple-php-from-validation/#findComment-1149084 Share on other sites More sharing options...
BlueSkyIS Posted December 18, 2010 Share Posted December 18, 2010 so, anyway... check to see if the form is posted. if it is posted, validate the values. if they do not validate, display the posted values in the form fields. if the form is NOT posted, initialize those values, so you display the POST'ed values or the initialized values in the form fields. This is terribly simplified and untested: <?php if ($_SERVER['REQUEST_METHOD'] == "POST") { $fname = $_POST['fname']; // Validation here // If no errors, process request and display success message or header() to another page. // else prepare the post'ed value for re-display $fname = htmlspecialchars(strip_slashes($_POST['fname')); } else { $fname = ''; } ?> somewhere in a form... <br /> <input type='text' name='fname' value='<?php echo $fname; ?>' /> Quote Link to comment https://forums.phpfreaks.com/topic/222080-simple-php-from-validation/#findComment-1149091 Share on other sites More sharing options...
laffin Posted December 18, 2010 Share Posted December 18, 2010 Send results back to your form, u can use $_GET <?php $username=isset($_GET['uname'])?$_GET['uname']:''; ?> <form action="form_action.php" method="post"> User name: <input type="text" name="uname" /><br /> <input type="submit" value="Submit" /> </form> in your process form <?php $uname=issset($_POST['uname'])?$_POST['uname']:''; if(!is_valid($uname)) header('Location: form.php?uname='.urlencode($uname)) well that should give u an idea of a pure php solution, but i would never send the password using this method (have them re-enter it) Note: Me & Blue posted about the same time. His Solution is based on an all in one form/processing script. The solution i presented here is for seperate form/processing. Both will work, just depends which system you implement. Quote Link to comment https://forums.phpfreaks.com/topic/222080-simple-php-from-validation/#findComment-1149092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.