获取复选框值php

时间:2016-06-21 06:47:57

标签: php arrays codeigniter-3

先生,好日子先生。请先检查我的脚本。

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-injars      bin/classes
-injars      libs
-outjars     bin/classes-processed.jar

# Using Google's License Verification Library 
-keep class com.android.vending.licensing.ILicensingService

# Specifies to write out some more information during processing. 
# If the program terminates with an exception, this option will print out the entire stack trace, instead of just the exception message.
-verbose

####################################################################################################
##############################  IBM MobileFirst Platform configuration  ############################
####################################################################################################
# Annotations are represented by attributes that have no direct effect on the execution of the code. 
-keepattributes *Annotation*

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keepattributes InnerClasses
-keep class **.R
-keep class **.R$* {
    <fields>;
}

# These options let obfuscated applications or libraries produce stack traces that can still be deciphered later on 
-renamesourcefileattribute SourceFile    
-keepattributes SourceFile,LineNumberTable

# Enable proguard with Cordova
-keep class org.apache.cordova.** { *; }
-keep public class * extends org.apache.cordova.CordovaPlugin

-keep class com.worklight.androidgap.push.** { *; }
-keep class com.worklight.wlclient.push.** { *; }
-keep class com.worklight.common.security.AppAuthenticityToken { *; }

# Enable proguard with Google libs
-keep class com.google.** { *;}
-dontwarn com.google.common.**
-dontwarn com.google.ads.**

# apache.http
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
-optimizations !class/merging/vertical*,!class/merging/horizontal*,!code/simplification/arithmetic,!field/*,!code/allocation/variable

-keep class net.sqlcipher.** { *; }
-dontwarn net.sqlcipher.**

-keep class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# These classes contain references to external jars which are not included in the default MobileFirst project.
-dontwarn com.worklight.common.internal.WLTrusteerInternal*
-dontwarn com.worklight.jsonstore.**
-dontwarn org.codehaus.jackson.map.ext.*
-dontwarn com.worklight.androidgap.push.GCMIntentService
-dontwarn com.worklight.androidgap.plugin.WLInitializationPlugin
-dontwarn com.worklight.wlclient.push.GCMIntentService
-dontwarn org.bouncycastle.**
-dontwarn com.worklight.androidgap.jsonstore.security.SecurityManager

-dontwarn com.worklight.wlclient.push.WLBroadcastReceiver
-dontwarn com.worklight.wlclient.push.common.*
-dontwarn com.worklight.wlclient.api.WLPush
-dontwarn com.worklight.wlclient.api.SecurityUtils

-dontwarn android.support.v4.**
-dontwarn android.net.SSLCertificateSocketFactory
-dontwarn android.net.http.*
######################################################################################################

-dontwarn android.**
-keep class android.**

-dontwarn com.android.**
-keep class com.android.**

-dontwarn com.google.**
-keep class com.google.**

所以我想要的是保存复选框值。现在我能做的是

    <div class="form-group">
       <label class="btn control-label col-sm-2" for="email">Developer</label>
       <label class="btn btn-info">
       <input name='pilihan[]' value='1' type="checkbox" autocomplete="off"> Konfigurasi Menu                                           <span class="glyphicon glyphicon-ok"></span></label>
       <label class="btn btn-info">
       <input name='pilihan[]' value='2' type="checkbox" autocomplete="off"> Konfigurasi User                                           <span class="glyphicon glyphicon-ok"></span>
       </label>
       <label class="btn btn-info">
       <input name='pilihan[]' value='16' type="checkbox" autocomplete="off"> User Akses                                            <span class="glyphicon glyphicon-ok"></span>
       </label>
    </div>
    <div class="form-group">
       <label class="btn control-label col-sm-2" for="email">Admin</label>
       <label class="btn btn-info">
       <input name='pilihan[]' value='1' type="checkbox" autocomplete="off"> Konfigurasi Menu                                           <span class="glyphicon glyphicon-ok"></span>
       </label>
       <label class="btn btn-info">
       <input name='pilihan[]' value='2' type="checkbox" autocomplete="off"> Konfigurasi User                                           <span class="glyphicon glyphicon-ok"></span>
       </label>
       <label class="btn btn-info">
       <input name='pilihan[]' value='16' type="checkbox" autocomplete="off"> User Akses                                            <span class="glyphicon glyphicon-ok"></span>
       </label>
    </div>
    <div class="form-group">
       <label class="btn control-label col-sm-2" for="email">Outlet</label>
       <label class="btn btn-info">
       <input name='pilihan[]' value='1' type="checkbox" autocomplete="off"> Konfigurasi Menu                                           <span class="glyphicon glyphicon-ok"></span>
       </label>
       <label class="btn btn-info">
       <input name='pilihan[]' value='2' type="checkbox" autocomplete="off"> Konfigurasi User                                           <span class="glyphicon glyphicon-ok"></span>
       </label>
       <label class="btn btn-info">
       <input name='pilihan[]' value='16' type="checkbox" autocomplete="off"> User Akses                                            <span class="glyphicon glyphicon-ok"></span>
       </label>
    </div>

我可以获得 [pilihan] => Array ( [0] => 1 [1] => 2 [2] => 16 ) ,但值为value

从上面的表单中可以看到freedeveloper&amp; admin

我的问题是,如何设置Outletdeveloper&amp;的价值。 admin

2 个答案:

答案 0 :(得分:1)

正如您在html标记中看到的那样,您正在为具有相同名称属性的所有角色创建输入,这将导致创建一个包含所有选定值的数组。在您的情况下,您应该创建pilihan[],但另外添加特定角色的键,例如:

显影剂:

 name="pilihan['developer'][]"

admin:

 name="pilihan['admin'][]"

出口:

 name="pilihan['outlet'][]"

上述结构将为您提供以下结果

Array
(
    [developer] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 16
        )

    [admin] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 16
        )

    [outlet] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 16
        )

)

接下来你可以做的是你可以选择特定的数组键(开发人员,管理员或插座)并将它们放在foreach循环中并获取它们的值。例如:

// this below will print all the roles's values
$data = $_POST['checkbox'];

foreach($data as $roles){
    print_r($roles);
}

用于访问特定角色值:

$data = $_POST['checkbox'];
// this will print each single values from the array of checkbox but with key role `developer`    
foreach($data['developer'] as $values){
    print_r($values);
}

答案 1 :(得分:0)

您可以将复选框值转换为foreach中的数组并插入

foreach($_POST['pilihan'] as $value) {
       print_r($value);
}