I have a bunch of values from checkboxes that are boolean. Al I want to do is set them to yes if they are 1 and no if they are 0.
My code fails, looks ok to me?
$item = $form_state['values']['item1'] == 1 ? 'Yes' : 'No';
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your checkboxes have value attribute equal to 1, it should be OK:
If you have not set these values or in all the cases you may just check, if they exists in
$_GETor$_POSTarray (assuming$form_stateis taken from there):The above example, should works for you. Keep in mind radio buttons and check boxes will not be set in
$_GETor$_POSTif they are not selected, at all, which also may generate Notice or Warning, if trying to access non-existing index.In older versions of php you might need to use
$_REQUEST.