Advertisement
Bakaburg1

PodsCMS input helper - chekboxes

May 7th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2. //checkboxes
  3.  
  4.         $comment = sanitize_text_field( $comment ); // cleans input
  5.  
  6.         $comment = str_replace(", ", ",", $comment); // cleans useless white spaces after puntuaction if present
  7.  
  8.         $choices = explode(",", $comment);
  9.  
  10.         $css_classes = str_replace(array(' ' . $coltype . ' ', ' pods_coltype_' . $coltype . ' '), array(' pick ', ' pods_coltype_pick '), $css_classes);
  11.  
  12.         ?>
  13.  
  14.         <div class="<?php echo esc_attr($css_classes); ?>" id="<?php echo esc_attr($css_id); ?>" style="border: none; height: auto">
  15.  
  16.         <?php
  17.        
  18.         $values = explode(",", $value); // retrieves set value and explodes it to array of set values
  19.  
  20.         foreach($choices as $key => $val) {
  21.                
  22.                 $selected = '';
  23.                 $active = '';
  24.  
  25.                 if (in_array($key, $values) && $value !== '') {
  26.                         $selected = ' CHECKED';
  27.                         $active = ' active';
  28.                 }
  29.                
  30.                 if( $val !== "[]"){
  31.                                         ?>
  32.                     <input type="checkbox" id="checkbox_<?php echo $name . '_' . $key; ?>" name="<?php echo $name . '[]'; ?>" class="checkbox-option<?php echo $active; ?>" value="<?php echo $key; ?>" data-value="<?php echo $key; ?>" <?php echo $selected; ?> />
  33.                     <label for="checkbox<?php echo $name . '_' . $key; ?>"><?php echo $val; ?></label><br />
  34.                                         <?php
  35.                 }
  36.                 else{
  37.                                         ?>
  38.                     <label for="text_<?php echo $name . '_' . $key; ?>">Altro: </label>
  39.                     <input type="text" id="text_<?php echo $name . '_' . $key; ?>" name="<?php echo $name . '_other'; ?>" class="textfield-option<?php echo $active; ?>" value="<?php echo ($val === '[]'? '': $val); ?>"/>
  40.                                         <?php
  41.                 }
  42.         }
  43.         ?>
  44.         </div>
  45.         <script type="text/javascript">
  46.         jQuery('#<?php echo $css_id; ?> input.checkbox-option').on('change', function(){
  47.             jQuery('#<?php echo $css_id; ?> input.checkbox-option').removeClass('active');
  48.             jQuery('#<?php echo $css_id; ?> input.checkbox-option:checked').addClass('active');
  49.         });
  50.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement