evlj Posted May 11, 2011 Share Posted May 11, 2011 Hi there once again, sry for previous wrong section, i guess this time i'm on the right place ;p Well i need following: I have few forms (input fields) with requested informations, also i have other .php file which i'm calling to send a form. Now i need to know how can i do a check for those fields if they are empty or not. If they are, i need to STOP submiting the form (calling the other .php). Codes: Form: <form name="f1" form method="post" action="posalji.php"/> Field: <input type="text" name="hp1" size="20"/> Submit: <input name="f1" type="image" src="registruj.png" onclick="if(f1.hp1.value.length==0) alert('Error: field can't be empty'); else f1.submit(); if(f1.hp2.value.length==0) alert('Error: field can't be empty'); else f1.submit();"/> There are more than one field, that's why you can see more errors in submit. Well all i need is "die" or "stop" calling the "posalji.php" from action above. Sry 4 poor english. Quote Link to comment https://forums.phpfreaks.com/topic/236115-little-help-with-submit-button-and-field-check/ Share on other sites More sharing options...
gristoi Posted May 11, 2011 Share Posted May 11, 2011 use some javascript on the client side and then some further validation on the server side: pop an id into each of the field tags and try something like var hpl = document.getElementById('hpl') Quote Link to comment https://forums.phpfreaks.com/topic/236115-little-help-with-submit-button-and-field-check/#findComment-1213876 Share on other sites More sharing options...
evlj Posted May 11, 2011 Author Share Posted May 11, 2011 Well i'm getting popup windows with errors, but whenever i click "ok" button on them, i'm getting to the "posalji.php". Basically that's not preventing from calling the other php. So all i need is to stop calling that one after the popup. Quote Link to comment https://forums.phpfreaks.com/topic/236115-little-help-with-submit-button-and-field-check/#findComment-1213879 Share on other sites More sharing options...
keepAway Posted May 11, 2011 Share Posted May 11, 2011 <form name="f1" form method="post" action=""/> <input type="text" name="hp1" size="20"/> <input type="submit" name="submit" value="Submit"> </form> <?php if (isset($_POST['submit'])) { if (empty($_POST['hp1'])) { echo "Empty field"; } else echo $_POST['hp1']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/236115-little-help-with-submit-button-and-field-check/#findComment-1213883 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.