Jump to content

user must pick one of 3 checkboxes


neeep

Recommended Posts

if (!isset($_POST['invoiceemployer']) && !isset($_POST['lodging'])){ && !isset($_POST['draft'])){

    echo "<span id='red'><font size='4'> Please pick invoice employer, Lodging or Draft:</font><br />$error</span>";

} else {

// now you need to figure out which one they clicked..

if (isset($_POST['invoiceemployer'])) {

// invoiceemployer day was selected

} else {

if (isset($_POST['lodging'])) {

//lodging was selected

}else

}

}

 

This isnt being accepted. It was working fine until I added the third option of draft.

 

My page wont load and I get this error... syntax error, unexpected T_BOOLEAN_AND

 

Any code suggestions? thanks.

 

Link to comment
Share on other sites

Your first line is a bit screwy.

if (!isset($_POST['invoiceemployer']) && !isset($_POST['lodging'])){ && !isset($_POST['draft'])){

should be

if (!isset($_POST['invoiceemployer']) && !isset($_POST['lodging']) && !isset($_POST['draft'])) {

Link to comment
Share on other sites

Thanks, I can't believe I didn't see that. I assumed the problem was bigger than just a stray bracket!

 

http://pastebin.com/m67818aba

 

here is my code..Im getting this weird error

 

Parse error: syntax error, unexpected $end in /public_html/kenny/form.php on line 518

 

I can't make sense of it. Can anyone see the problem?

 

Link to comment
Share on other sites

Try this as your code block.. I did a few corrections

if (!isset($_POST['invoiceemployer']) && !isset($_POST['lodging']) && !isset($_POST['draft'])){
    echo "<span id='red'><font size='4'> Please pick invoice employer, Lodging or Draft:</font><br />$error</span>";
} else {
// now you need to figure out which one they clicked..
if (isset($_POST['invoiceemployer'])) {
// invoiceemployer day was selected
} elseif (isset($_POST['lodging'])) {
//lodging was selected
} else {

}
}

 

Do you only want 1 of them selected at any one time? or can they choose more than 1?

If they can only choose 1 you should use radio buttons and we can make this code alot smaller

Link to comment
Share on other sites

Well for the sake of learning ill give you a little snippet of a radio usage

HTML

<input type="radio" name="thebox" id="invoiceemployer" value="invoiceemployer" />
<input type="radio" name="thebox" id="draft" value="draft" />
<input type="radio" name="thebox" id="lodging" value="lodging" />

then in PHP after the form is posted you can do this..

if (isset($_POST['thebox'])) {
echo 'The selected radio was: '.$_POST['thebox'];
} else {
echo "<span id='red'><font size='4'> Please pick invoice employer, Lodging or Draft:</font><br />$error</span>";
}

Simple huh?

Link to comment
Share on other sites

The 'name' attributes on your radio buttons must be the same..

Something like 'payment' would be appropriate..

Then for each of the radios you need to set the 'value' to what is it.. at the moment you have the name as the value :D

 

Once you have changed the name to 'payment'

 

your php will check thast with

if (isset($_POST['payment'])) {

} else {

}

Link to comment
Share on other sites

You should only build your email message AFTER you have validated the inputs..

These


$emailMessage .= "\ninvoice employer: " . (isset($_POST['invoiceemployer']));
$emailMessage .= "\nlodging: " . (isset($_POST['lodging']));
$emailMessage .= "\ndraft: " . (isset($_POST['draft']));

are not there anymore you can make it more appropriate and put

$emailMessage .= "\nPayment Type: ".$_POST['payment'];

but definitely validate your form values first.. its just better coding practice..

Link to comment
Share on other sites

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.