ghi572000 Posted March 12, 2011 Share Posted March 12, 2011 Hi, I'm no pro at PHP but I am trying to get a drop down menu to a authenticate before moving to the next part of the form. What I want is once a selection has been made, ONLY THEN can the user move on, OTHERWISE a message echo appears. This is the html menu box <select size="1" name="title"> <option>Please Select</option> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Ms">Ms</option> <option value="Dr">Dr</option> </select> Then this is what I have in the form PHP: $visitortitle = $_POST['visitortitle']; if ( HOW DO I GET THIS PART TO AUTHENTICATE AN OPTION HAS BEEN SELECTED? ) { echo "<p>Please enter a title correctly<br />before you try submitting the form again.</p>\n"; die ( '<a href="pef.html">click here go back and try again</a>' ); echo $id;} If anyone can help me sort out this part of the form I can move on as the rest is working fine? Thanks Gary Link to comment https://forums.phpfreaks.com/topic/230445-drop-down-menu-select/ Share on other sites More sharing options...
Alex1646 Posted March 12, 2011 Share Posted March 12, 2011 To validate form data without it getting submitted you have to use JavaScript. This is because PHP is interpreted on the server, so you have to make a request to the server for it to work(unless you use AJAX but that is a different story). Try looking into JavaScript form validation. Link to comment https://forums.phpfreaks.com/topic/230445-drop-down-menu-select/#findComment-1186695 Share on other sites More sharing options...
ghi572000 Posted March 12, 2011 Author Share Posted March 12, 2011 Thanks Alex, I thought I might have to use some javascript. Once I find some script to use how should I write the if PHP part or does this depend on the script I use? Link to comment https://forums.phpfreaks.com/topic/230445-drop-down-menu-select/#findComment-1186698 Share on other sites More sharing options...
Eliasen Posted March 12, 2011 Share Posted March 12, 2011 is it not something like: if (empty($_POST['title'])) { echo "<p>Please enter a title correctly<br />before you try submitting the form again.</p>\n"; die ( '<a href="pef.html">click here go back and try again</a>' ); echo $id;} i could be wrong. Edit: Right, didn't read the question properly. Link to comment https://forums.phpfreaks.com/topic/230445-drop-down-menu-select/#findComment-1186705 Share on other sites More sharing options...
ghi572000 Posted March 12, 2011 Author Share Posted March 12, 2011 Okay, thanks it sounds like this is going to be a bit difficult and a bit over my head, however is there a easier way just for a selection to be made and then the user is able to move on to the next part of the form? Unless anyone can show me an example of how I could use the AJAX option detailed? Link to comment https://forums.phpfreaks.com/topic/230445-drop-down-menu-select/#findComment-1186707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.