bogdaniel Posted October 12, 2008 Share Posted October 12, 2008 hello.. i need a small help from you guys.. and i'm trying to make a function for form validating and i'm stuck on form errors i've got no clue and no ideea how should i do that that part if user is incorect to show me next to that field an error or if password is incorect to show me next to password field an other erorr please can you help me ? thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/128088-solved-form-handling/ Share on other sites More sharing options...
genericnumber1 Posted October 12, 2008 Share Posted October 12, 2008 The easiest method is to post onto the page with the form.. so on form.php <?php if($_POST['submit'] == 'true') { // Handle form data here, things like is the username the right size, etc. and set an error message // For example... $errors = array(); if(empty($_POST['username']) || strlen($_POST['username']) > 9) { $errors['username'] = 'Your username is not the right length'; } } ?> <form method="POST" action="form.php"> Username: <input type="text" name="username" maxlength="9" /> <?php echo (isset($errors['username'])) ? $errors['username'] : '' ?><br /> <input type="submit" name="submit" value="true" /> </form> Of course there are other methods to do this, but this is the most simple. Quote Link to comment https://forums.phpfreaks.com/topic/128088-solved-form-handling/#findComment-663354 Share on other sites More sharing options...
budimir Posted October 12, 2008 Share Posted October 12, 2008 Seems to me you will need to use javascript or AJAX for thing you are asking for. There are plenty of simple scripts on Google. Try Google for: "javascript form validation" Cheers Quote Link to comment https://forums.phpfreaks.com/topic/128088-solved-form-handling/#findComment-663393 Share on other sites More sharing options...
genericnumber1 Posted October 12, 2008 Share Posted October 12, 2008 Seems to me you will need to use javascript or AJAX for thing you are asking for. There are plenty of simple scripts on Google. Try Google for: "javascript form validation" Cheers Yes, if he wants real-time validation of input (every time the user puts in a char it tells him if the value is valid) he should use javascript. I'd recommend LiveValidation... http://www.livevalidation.com/ He still will want to use server-side validation though, such as in my example above, since people could very easily disable javascript. http://www.livevalidation.com/ To reiterate, javascript validation is convenient, not secure. Quote Link to comment https://forums.phpfreaks.com/topic/128088-solved-form-handling/#findComment-663396 Share on other sites More sharing options...
bogdaniel Posted October 12, 2008 Author Share Posted October 12, 2008 thank you very much for your replys now i have an ideea how should i do and stuff like that and that java ideea just get me a crazy ideea ) thanks again Bogdan. Quote Link to comment https://forums.phpfreaks.com/topic/128088-solved-form-handling/#findComment-663422 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.