Eggzorcist Posted August 25, 2009 Share Posted August 25, 2009 I'm wondering wether it's possible that if there is an error as in if $error isset, it will stay on this page displaying the error otherwise, it will go to the destined action='register.php' is this possible? if so, how would i be doing this? Thanks a bunch! Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/ Share on other sites More sharing options...
merck_delmoro Posted August 25, 2009 Share Posted August 25, 2009 on your place onSubmit("return action();") on your <form> and make a function named action() or any thing you want to name it dn make a if else condition for your validation if validation creates an error return false; and if no errors return true; Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906243 Share on other sites More sharing options...
Eggzorcist Posted August 26, 2009 Author Share Posted August 26, 2009 so on the register button, the onclick? I'm not sure if I understand this technique... Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906259 Share on other sites More sharing options...
Eggzorcist Posted August 26, 2009 Author Share Posted August 26, 2009 So you mean if I create a onSubmit, the onSubmit function will pass before the action? meaning if Onsubmit = false it wont submit? and if its true, it full go to the action? Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906261 Share on other sites More sharing options...
merck_delmoro Posted August 26, 2009 Share Posted August 26, 2009 yup Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906263 Share on other sites More sharing options...
merck_delmoro Posted August 26, 2009 Share Posted August 26, 2009 place onSubmit("return action();") on your <form> and make a function named action() or any thing you want to name it dn make a if else condition for your validation if validation creates an error return false; and if no errors return true; Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906267 Share on other sites More sharing options...
Eggzorcist Posted August 26, 2009 Author Share Posted August 26, 2009 Though it seems like the function has to be in javascript, it only works when it is. I tried with a php function but nothing worked. Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906274 Share on other sites More sharing options...
merck_delmoro Posted August 26, 2009 Share Posted August 26, 2009 Sorry I forgot to tell you that ^^ yup the function was a JavaScript function Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906276 Share on other sites More sharing options...
Eggzorcist Posted August 26, 2009 Author Share Posted August 26, 2009 Well, is there a way to create a regex style validation? So basically if I already have if (!preg_match("/\A[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/", $email)){ $Error .= "Email Address Must Be In format: [username]@[domain].[extension] <br />"; } is there a javascript way of doing this? My javascript is pretty bad Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906281 Share on other sites More sharing options...
redarrow Posted August 26, 2009 Share Posted August 26, 2009 what are you try to validate mate, what email what? Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906285 Share on other sites More sharing options...
Eggzorcist Posted August 26, 2009 Author Share Posted August 26, 2009 I'm trying to validate, firstly, a name more than 3 letters. and an email. Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906288 Share on other sites More sharing options...
redarrow Posted August 26, 2009 Share Posted August 26, 2009 do u understand this mate look <?php $name="redarrow"; if(preg_match("/^[a-z]{3}$/",$name)){ echo "correct name is 3 letters long"; exit; }else{ echo "no the name was more then 3 letters long"; exit; } ?> Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906293 Share on other sites More sharing options...
Eggzorcist Posted August 26, 2009 Author Share Posted August 26, 2009 Yes, I do. However, this needs to be in javascript to be able to use the onSubmit html function, because I'm trying to use the validation before the action which leads off to another file. Is there a way to implement the php regex prior the action(register.php) file? Thanks Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906294 Share on other sites More sharing options...
merck_delmoro Posted August 26, 2009 Share Posted August 26, 2009 read this article http://javascript.internet.com/forms/email-validation---basic.html Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906299 Share on other sites More sharing options...
mvpetrovich Posted August 26, 2009 Share Posted August 26, 2009 I think you were asking for something like this. Submit the form to the same page then: <?php if (isset($error) { echo "Error Found: $error"; } else { header('Location: register.php'); } // ... redo form ?> Link to comment https://forums.phpfreaks.com/topic/171869-form-validation-with-2-actions-if-error-or-not/#findComment-906541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.