Jump to content

[SOLVED] isset and else


psquillace

Recommended Posts

Hello All:

 

I am using a form that when people fill out on my site goes into my account at Constant Contacts. It works fine however, I am trying to add a checkbox to the end of the form by the submit button that says, Opt In.

 

This is where the customer can opt in for special catalogs we mail. Anyhooo, I have it saying

 

<? if (isset($optmessage)) {$_POST["Custom_field_3"]}else{$_POST[]} ?>

 

but I confused myself I think because i do not have it what to post if NOTset or else.

 

I hope this all makes sense, I am kind of new to php and am a little lost.

 

Thanks,

 

Paul

Link to comment
https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/
Share on other sites

Checkboxes do not submit a value if they are not checked when a form is submitted. They only send a value when they are. So if you have a checkbox in your form called cbx1 and it was checked thenyou'll be able to use $_POST['cbx1'] variable in the processing script, however if it wasn't checked when the form was submitted then $_POST['cbx1'] will not exist.

 

So you need to do is is check to see if the $_POST['your_checkbox_name_here'] variable exists in your code.

Link to comment
https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/#findComment-420634
Share on other sites

yes the variable i have set for my check box is 'optedin' but I would still need it to return something because of the people who will be looking at the final product will be looking for a Yes or No.

 

is there a way to have a 'optedin' = FALSE; $optedin = NO or something?

 

thanks for you help

 

Paul

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/#findComment-420741
Share on other sites

Use:

$optedin = (isset($_POST['optedin'])) ? 'YES' : 'NO';

 

That will set $optedin to YES if $_POST['optedin'] exists (meaning the checkbox has been checked), otherwise it will set it to NO if $_POST['optedin'] does not exist (not checked).

Link to comment
https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/#findComment-420823
Share on other sites

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.