PHP how to combine multiple if-statements into one function -
based on checkbox value form add subscribers corresponding list, can't save more 1 value.
how merge, in order, select , save more 1 checkbox value?
if(isset($_post['checkbox_list']) && in_array('austin metro', $_post['checkbox_list'])){ $listid = '3'; if ($listid){ $indeed_mail->indeed_wysija_subscribe( $listid, $email ); } break; } else if(isset($_post['checkbox_list']) && in_array('central austin', $_post['checkbox_list'])){ $listid = '4'; if ($listid){ $indeed_mail->indeed_wysija_subscribe( $listid, $email ); } break; } else if(isset($_post['checkbox_list']) && in_array('georgetown', $_post['checkbox_list'])){ $listid = '5'; if ($listid){ $indeed_mail->indeed_wysija_subscribe( $listid, $email ); } break; }
this might you're looking for... ?
$myvalues = array('austin metro','central austin','georgetown'); $myids = array('3','4','5'); if (isset($_post['checkbox_list']) && array_search($_post['checkbox_list'], $myvalues) !== false) { $index = array_search($_post['checkbox_list'], $myvalues); $indeed_mail->indeed_wysija_subscribe( $myids[$index], $email ); } edit : read comment above...
to grab checkboxes array use :
<input type="checkbox" name="checkbox_list[]" value="austin metro"> <input type="checkbox" name="checkbox_list[]" value="central austin"> <input type="checkbox" name="checkbox_list[]" value="georgetown"> then
foreach($_post['checkbox_list'] $check) { // stuff explained above... if (isset(check) && array_search($check, $myvalues) !== false) { $index = array_search($check, $myvalues); $indeed_mail->indeed_wysija_subscribe( $myids[$index], $email ); } }
Comments
Post a Comment