psquillace Posted December 21, 2007 Share Posted December 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/ Share on other sites More sharing options...
wildteen88 Posted December 21, 2007 Share Posted December 21, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/#findComment-420634 Share on other sites More sharing options...
psquillace Posted December 21, 2007 Author Share Posted December 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/#findComment-420741 Share on other sites More sharing options...
wildteen88 Posted December 21, 2007 Share Posted December 21, 2007 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). Quote Link to comment https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/#findComment-420823 Share on other sites More sharing options...
psquillace Posted December 21, 2007 Author Share Posted December 21, 2007 wow, thanks wildteen! although I am not sure what the ? is for, have not learned that much yet about php but I am sure this will work. thanks for your help Paul Quote Link to comment https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/#findComment-420827 Share on other sites More sharing options...
revraz Posted December 21, 2007 Share Posted December 21, 2007 It's a IF/ELSE statement wow, thanks wildteen! although I am not sure what the ? is for, have not learned that much yet about php but I am sure this will work. thanks for your help Paul Quote Link to comment https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/#findComment-420830 Share on other sites More sharing options...
psquillace Posted December 21, 2007 Author Share Posted December 21, 2007 thanks revraz I just looked it up on php.net. go figure.... Quote Link to comment https://forums.phpfreaks.com/topic/82701-solved-isset-and-else/#findComment-420837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.