unplugged_web Posted October 5, 2007 Share Posted October 5, 2007 I have a form and the results are being sent to a database, but I wanted to know if it is possible to make one of the fields compulsory so that someone is prompted if to file it in if they don't put anything in? I've noticed that most people aren't adding anything to that field, but want them to.ThanksLucy Link to comment Share on other sites More sharing options...
shujjah Posted October 5, 2007 Share Posted October 5, 2007 you can use if statmentslike if ( $name == "" ) || ( $email == "" ) || ($whatever == "" ){echo "you missed out the a field "}else{whatever script u wannt run like add the data to the databse} Link to comment Share on other sites More sharing options...
unplugged_web Posted October 5, 2007 Author Share Posted October 5, 2007 you can use if statmentslike if ( $name == "" ) || ( $email == "" ) || ($whatever == "" ){echo "you missed out the a field "}else{whatever script u wannt run like add the data to the databse}Thanks, I'll give that a go Link to comment Share on other sites More sharing options...
user4fun Posted October 6, 2007 Share Posted October 6, 2007 The problem with that is, you have to create a nother page error.php for example to diplay the, sorry you missed another page comment.i like to use javascript to do that, so it would prompt the user. <??><script language="javascript" type="text/javascript">function validateForm(register){if(""==document.forms.register.email.value){alert("Please enter your email address.");return false;}repeat for more fields} </script> <form name="register" method="post" action="registration_confirm.php" onSubmit="return validateForm(register);"><input type="text" name="email" size="30" value=""></form> Link to comment Share on other sites More sharing options...
Synook Posted October 6, 2007 Share Posted October 6, 2007 But careful, users can always disable JavaScript, thereby submitting their invalid form. For ease-of-use, you can use JS, but always have a server-side fallback. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 7, 2007 Author Share Posted October 7, 2007 Thank everybody for your help. I'll try both the JS ans server-side methods Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.