Derleek Posted May 15, 2008 Share Posted May 15, 2008 ok, so i have developed a script for validating user input? I want to make it so that if a user does not enter the data correctly he/she does not have to fill it all out again. How would i do this? I'm just not quite sure where to find a tutorial on this Quote Link to comment Share on other sites More sharing options...
revraz Posted May 15, 2008 Share Posted May 15, 2008 You set your INPUT values to the $_POST['data'] variables. Quote Link to comment Share on other sites More sharing options...
piyushsharmajec Posted May 15, 2008 Share Posted May 15, 2008 you validate either by javascript or either by php. By php you have to check all get or post data with corrected values. For javascript you have to validate by reguler expression. For this help either go to w3school.com Quote Link to comment Share on other sites More sharing options...
Derleek Posted May 15, 2008 Author Share Posted May 15, 2008 How exactly would i set my input value's to the $_POST variables? is there any way you could show me an example of what you mean? Quote Link to comment Share on other sites More sharing options...
piyushsharmajec Posted May 16, 2008 Share Posted May 16, 2008 This is basically dreamweaver code for login section. Dont be panic if you cant understand most of stuffm, only view basic code that is mark up. This is for login section in which if username and password from mysql table admin are not mathced than it gives error as by get method. I dont write code fully here. <?php require_once('../Connections/mycon.php'); ?> <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "donor.php"; $MM_redirectLoginFailed = "index.php?invalid=1"; $MM_redirecttoReferrer = false; mysql_select_db($database_mycon, $mycon); $LoginRS__query=sprintf("SELECT uername, password FROM admin WHERE uername='%s' AND password='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $mycon) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> <?php if(isset($_GET['invalid']) && $_GET['invalid']==1) { ?> <table> <tr class="box"> <td colspan="2" bgcolor="#FFFFCC"><div align="center"><span style="color:#FF0000; font-size:14px;" > <?php echo "Invalid Username/Password."; ?> </span></div></td> </tr> </table> <?php } ?> Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 16, 2008 Share Posted May 16, 2008 you validate either by javascript or either by php. No. You always validate with PHP. You can additionally validate with JavaScript. But you can never, ever, not in a million years, use only JavaScript for your validation. If you follow the links in my signature, I have provided a couple of simple tutorials on form processing. As part of the tutorial I show how to re-populate the form fields with previously submitted data. I only do this for a single text field, but the principle applies easily to other types of fields. For select fields, when creating the options you check if an option's value is the same as the one in $_POST and if it is, add selected to the option tag. <?php $opts = array( 1, 2, 3 ); echo '<select name="mySelect">'; foreach($opts as $opt){ echo sprintf('<option value="%s"%s>', $opt, $opt == $_POST['mySelect'] ? ' selected' : ''); } echo '</select>'; ?> The same thing applies to check boxes, only you use checked instead of selected. For textareas, you just place the default between the tags: echo sprintf('<textarea name="myText">%s</textarea>', $_POST['myText']); Quote Link to comment 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.