如何在wordpress中保存多个复选框的值 [英] how to save multiple checkboxes value in wordpress

查看:22
本文介绍了如何在wordpress中保存多个复选框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的复选框代码.

<p class="full_form"><label for="prop_category"><?php _e('We are into','wpestate');?></label>
        <input type="checkbox" id="architecture" size="80" name="service_name[]" value="architecture" >Architecture
        <input type="checkbox" id="builder_developer" size="80" name="service_name[]" value="builder_developer">Builders and Developeres
        <input type="checkbox" id="material_supplier" size="80" name="service_name[]" value="material_supplier">Material Supplier
        <input type="checkbox" id="contractor" size="80" name="service_name[]" value="contractor">Contractor
        <input type="checkbox" id="int_decorator" size="80" name="service_name[]" value="int_decorator">Interior Decorator
        <input type="checkbox" id="prop_finance" size="80" name="service_name[]" value="prop_finance">Property Finance
        <input type="checkbox" id="prop_legal_ad" size="80" name="service_name[]" value="prop_legal_ad">Property Legal Advisor
        <input type="checkbox" id="prop_valuer" size="80" name="service_name[]" value="prop_valuer">Property Valuer
        <input type="checkbox" id="vastu_consult" size="80" name="service_name[]" value="vastu_consult">Vaastu Consultant

如何在 wordpress postmeta 表中保存多个复选框?我应该将它们保存为数组吗?表单提交后如何访问它们?以及如何在编辑时显示选定的复选框值?

How Do I save multiple checkboxes in wordpress postmeta table? Should I save them as array? How Do I access them after form submit? And how do I display selected checkbox value while editing??

推荐答案

试试这个方法HTML 代码

<p class="full_form"><label for="prop_category">We are into</label>
            <input type="checkbox" id="architecture" size="80" name="service_name[]"  value="Architecture" >Architecture
            <input type="checkbox" id="builder_developer" size="80" name="service_name[]"  value="Builders and Developeres">Builders and Developeres
            <input type="checkbox" id="material_supplier" size="80" name="service_name[]" value="Material Supplier">Material Supplier
            <input type="checkbox" id="contractor" size="80" name="service_name[]" value="Contractor">Contractor
            <input type="checkbox" id="int_decorator" size="80" name="service_name[]" value="Interior Decorator">Interior Decorator
            <input type="checkbox" id="prop_finance" size="80" name="service_name[]" value="Property Finance">Property Finance
            <input type="checkbox" id="prop_legal_ad" size="80" name="service_name[]"  value="Property Legal Advisor">Property Legal Advisor
            <input type="checkbox" id="prop_valuer" size="80" name="service_name[]"  value="Property Valuer">Property Valuer
            <input type="checkbox" id="vastu_consult" size="80" name="service_name[]" value="Vaastu Consultant">Vaastu Consultant

提交保存代码

<?php 
        //submit code 
          if(isset($_POST['service_name'])  ){
              $data=serialize($_POST['service_name']);

              update_post_meta($postid, 'service_name', $data);
          }
        ?>

编辑代码

<?php 
        //edit code

            $data=get_post_meta($postid, 'service_name');
            //$data=unserialize($data[0]);
            $data=$data[0];
            print_r($data);

        ?> 

        <input type="checkbox" id="architecture" size="80" name="service_name[]"  value="Architecture" <?php if(in_array('Architecture',$data)  ){echo "checked";} ?> >Architecture



//other checkbox put as this 

in_array 检查一下

这篇关于如何在wordpress中保存多个复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆