Early73
Early73

Reputation: 503

extjs 6 checkbox group getValue

I need to post the values of selected checkboxes in a checkbox group to the server. Ultimately I am not worried about the checkbox name but just the list of input values.

How do I post these to the server? if I use getValue() I get an ext object features, using ext.encode on the object I get this

{"feature-3":"3","cfeature-5":"5","feature-7":"7",
"feature-10":"10","feature-12":"12","feature-13":"13",
"feature-15":"15","feature-18":"18"}

I don't care if the data is parsed before or after the post to the server but I need to be able to loop through the data in php and get 3..5..7 etc as the values when I loop through the data.

what is the best way to send checkboxgroup values to the server? I am using an ajax call like this :

 Ext.Ajax.request({
        scope: this,
        timeout: 1200000,
        url: './data/saveUsedFeatures.php',
        method: 'POST',
        params: {
 features: features
 },

I need to understand how to both send the data and process it in php.

Upvotes: 0

Views: 617

Answers (1)

LightNight
LightNight

Reputation: 851

First of all encode your object features to get json string.

Ext.Ajax.request({
    scope: this,
    timeout: 1200000,
    url: './data/saveUsedFeatures.php',
    method: 'POST',
    params: {
    features: Ext.encode(features)
}

and on server side decode that string to get array:

<?php
    $arr= json_decode($_REQUEST["features"],true);
    foreach($arr as $v){
        //your logic here
    }
?>

Or

Second option is to use form.Submit() instead Ext.ajax. you will get array of checkbox group values. for example if your checkboxgroup has property name:'checkboxgroup' on server side:

<?php
    foreach($_REQUEST["checkboxgroup"] as $v){
       //your logic
    }
?>

Upvotes: 1

Related Questions