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
https://forums.phpfreaks.com/topic/188571-user-must-pick-one-of-3-checkboxes/
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'])) {

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?

 

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

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?

http://pastebin.com/m328ff01e

 

There's my code. The relevant stuff is at 133-137 and 386-396

 

The radio buttons arent working. as you can see at the bottom of this page.. http://www.fishpondmedia.com/kenny/form.php

 

can you see what's wrong?

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 {

}

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

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.