mardi 4 janvier 2022

Checkbox "unchecked" does not recognize it in php and Wordpress [duplicate]

I am having a problem, when the condition is met $field_id_value == "1" the checkbox is marked, but when unchecking it php does not recognize it as uncheked, it is always in checked

I've used if (! Isset ($ _ POST ['categories'])) but it still doesn't recognize it

 function wpdocs_unsub_page_callback() {

         
         ?>

                  <form method="post" action="<?php echo esc_html('?page=categoriasrelacionadas'); ?>">
     <div>
                    <input type="button" onclick="checkAll()" value="CHECK ALL">
                    <input type="reset" value="UNCHECK ALL">
                </div>
              <?php
    $cat_argtos=array(
      'orderby' => 'name',
      'order' => 'ASC'
       );
    $categorias=get_categories($cat_argtos);
    foreach($categorias as $categoria) {
    $args=array(
      'showposts' => -1,
      'category__in' => array($categoria->term_id),
      'caller_get_posts'=>1
    );
    $entradas=get_posts($args);
        
       $field_id_value = get_option($categoria->term_id);
  if($field_id_value == "1"){ $field_id_checked = 'checked="checked"'; } else { $field_id_checked=" ";}
    echo '<p>' .$categoria->name.'<input id="myCheck'.$categoria->term_id.'" type="checkbox" '.$field_id_checked.' class="check3" name="categorias[]"  value="'.$categoria->term_id.'" />  </p> ';

    
    }
         
         
         ?>
        
                    </p>
            <!-- #universal-message-container -->
     
            <?php
                wp_nonce_field( 'acme-settings-save', 'acme-custom-message' );
                submit_button();
            
        
    
     
    
    
            ?>
    
        </form>
    
    
    
         <?php 
        if(isset($_POST['submit'])){//Validacion de envio de formulario
    
   
    
         if (!isset($_POST['categorias'])) {
        
             $checked = 0;
        }
         else {  $checked = 1;} 
    foreach($_POST['categorias'] as $selected){
        
        
    
       
        update_option($selected, $checked);
    
        
        
    echo $selected."</br>";// Imprime resultados
    }
    
    }
         
     }

I have tried everything until unchecked with javascript but the checkbopx is still checked




Aucun commentaire:

Enregistrer un commentaire