wordpress add option checkbox and retrive data

 <form method=“post” action=“”>

<span>Select languages</span><br/>
<input type=“checkbox” name=‘lang[]’ value=“PHP”> PHP <br/>
<input type=“checkbox” name=‘lang[]’ value=“JavaScript”> JavaScript <br/>
<input type=“checkbox” name=‘lang[]’ value=“jQuery”> jQuery <br/>
<input type=“checkbox” name=‘lang[]’ value=“Angular JS”> Angular JS <br/>

<input type=“submit” value=“Submit” name=“submit”>
</form>

<?php
if(isset($_POST[‘submit’])){

if(!empty($_POST[‘lang’])) {

foreach($_POST[‘lang’] as $value){
echo “value : “.$value.‘<br/>’;
}

}
update_option( ‘pnr_post_type’,$_POST[‘lang’] );
}
?>
get value and check

$posttype = get_option( ‘pnr_post_type’ );
print_r($posttype);

check the value exist or not

echo var_dump(in_array(‘PHP’, $posttype)); // TRUE
echo var_dump(in_array(19, $posttype)); // TRUE




Leave a Comment

Your email address will not be published. Required fields are marked *