Jump to content

Drop down Menu Select?


ghi572000

Recommended Posts

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

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.

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.

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.