Jump to content

Recommended Posts

I'm having trouble making a couple different types of fields on a <FORM> work -- when the form is processed, I have 2 types of fields I am trying to ensure the person clicks.  If they don't fill out or click the appropriate field, the web page should notify them of this. 

name and address are simple fields where a person fills that in.

ordertype is one of two radio buttons a person clicks on.  I am detecting the fields that need to be populated, but cannot seem to detect when a radio button is not clicked on.

 

What I have right now in the php form processor:

 

$name = $_POST['name'];

$address = $_POST['address'];

$order = $_POST['ordertype'];

 

if(empty($name) || empty($address)) {

echo "Please fill in all required fields.\n";

}

 

if(empty($order)) {

echo "Please click on an order type.\n";

}

 

The second check for $order never seems to get processed for some reason.

 

 

Alternatively, is there a good PHP way to check to see that a field is populated and if not, create a popup tiny window that alerts the person that they need to populate such and such a field instsead of giving them a blank webpage as above and requiring them to click on the back arrow of the browser?  Any examples would be excellent.

 

Thank you.

 

Link to comment
https://forums.phpfreaks.com/topic/73206-multiple-required-fields/
Share on other sites

$name = $_POST['name'];
$address = $_POST['address'];
$order = $_POST['ordertype'];

 

Try this instead:

 

<?php
$error = "We have detected an error. Please fix the following:<br>";
$error_check = 0;

if(!isset($_POST['name')){//doesn't exist
$error .= "<br>No name has been filled in.";
$error_check++;
}
if(!isset($_POST['address'])){//doesn't exist
$error .= "<br>No address has been filled in.";
$error_check++;
}
if(!isset($_POST['ordertype']){//doesn't exist
$error .= "<br>No radio button has been selected.";
$error_check++;
}

if($error_check != 0){
die($error);
} else {//everything is a-ok.
return true;
}
?>

The posted code is returning a blank page for some reason.

Here is what I have -- not sure why it's blank as I cannot see an error in here:

 

<?php

 

$name = $_POST['name'];

$address = $_POST['address'];

$order = $_POST['ordertype'];

 

if (eregi('http:', $comment)) {

die ("No URLs are allowed in these fields!");

}

 

$error = "We have detected an error. Please fix the following:<br>";

$error_check = 0;

 

if(!isset($_POST['name')){//doesn't exist

$error .= "<br>No name has been filled in.";

$error_check++;

}

if(!isset($_POST['address'])){//doesn't exist

$error .= "<br>No address has been filled in.";

$error_check++;

}

if(!isset($_POST['ordertype'];)){//doesn't exist

$error .= "<br>No radio button has been selected.";

$error_check++;

}

 

if($error_check != 0){

die($error);

} else {//everything is a-ok.

return true;

}

 

// email results and send customer to "Thank You" page.

 

?>

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.