Getting Data from Post Array in Codeigniter

Getting data from post array in CodeIgniter

Array derefencing from function calls isn't supported by PHP. It's implemented in the SVN trunk version of PHP, so it will likely make it into future versions of PHP. For now you'll have to resort to what you're doing now. For enumerated arrays you can also use list:

list($day) = $this->input->post("days");

See: http://php.net/list

How to get value post array in codeigniter?

Change the way name of checkbox written as follows,

<?php foreach ($doc as $row) { ?>
<label>
<input name="size[]" type="checkbox" value="<?php echo $row['doc']; ?
>">  <?php echo $row['doc']; ?>
</label>
<?php } ?>

And in post method,

$size_arr = $this->input->post('size');
foreach($size_arr as $v){
echo $v;
}

if for some reason it is not working then check with,

$size_arr = $_POST['size'];
foreach($size_arr as $v){
echo $v;
}

EDIT

One more alternative,

$arr = $this->input->post();
$size_arr = $arr['size'];
foreach($size_arr as $v){
echo $v;
}

Core version,

$arr = $_POST;
$size_arr = $arr['size'];
foreach($size_arr as $v){
echo $v;
}

How can I get post data into an array in CodeIgniter? post items are arrays

$id = $this->input->post('id');
$sort_order = $this->input->post('sort_order');
$data = array();
foreach($id as $key=>$val)
{
$data[] = array('id'=>$val,'sort_order'=>$sort_order[$key]);
}

How to post array[][] in codeigniter

In an html Form you can add a field with name having double square brackets. Like:

<input name="myVal[][]" />

Then post this into a form to php.
In you php file write:

echo '<pre>';print_r($_POST);'</pre>';

You will see posted fields there. You can get this posted data in codeigniter using:

 $this->input->post('myVal');

How to get value from checkbox and post array in codeigniter?

I have tried this code
in your Page_model put this code.

public function input_values(){
$checkbox = implode(',', $this->checkBox());
$data = array(
'lang_id' => $this->input->post('lang_id', true),
'title' => $this->input->post('title', true),
'slug' => $this->input->post('slug', true),
'page_description' => $this->input->post('page_description', true),
'page_keywords' => $this->input->post('page_keywords', true),
'page_content' => $this->input->post('page_content', false),
'parent_id' => $this->input->post('parent_id', true),
'page_active' => $this->input->post('page_active', true),
'title_active' => $this->input->post('title_active', true),
'breadcrumb_active' => $this->input->post('breadcrumb_active', true),
'need_auth' => $this->input->post('need_auth', true),
'howmany_people' => $this->input->post('howmany_people', true),
'difficulty' => $this->input->post('difficulty', true),
'howmany_time' => $this->input->post('howmany_time', true),
'location' => $this->input->post('location', true),
'subcat_recip_id' => $checkbox
);
}

public function checkBox(){
$count = count($_POST['subcat_recip_id']);
for($n=0; $n<$count; $n++){
$checkbox[$n] = $_POST['subcat_recip_id'][$n];
}
return $checkbox;
}

hopefully it helps

CodeIgniter: Getting data from form array into post array

Why not just do:

$data = $this->input->post('options');

Then $data['is_rental'] should == 1

Can codeigniter receive post array?

Have you checked your HTML? You should include the [] synthesis into the name attribute to create an array, for example

<input type="text" value="something..." name="postArray[]" />
<input type="text" value="something..." name="postArray[]" />

Output of print_r($this->input->post()):

Array (

[0] => something...
[1] => something...
)

If you want to include name keys instead of indexed array, you can use this method:

<input type="text" value="something..." name="postArray[t1]" />
<input type="text" value="something..." name="postArray[t2]" />

Output of print_r($this->input->post()):

Array (

[t1] => something...
[t2] => something...
)

How to get and count post variable (array) in CodeIgniter?

You can count all element with 'kd_obat_' using this code:

$count=0;
foreach($arr as $key=>$value){
$pos = strpos($key,'kd_obat_');
if($pos!==false){
$count++;
}else{
continue;
}
}
echo $count;

How get data JSON multi array via POST in php

Tge post method returns an associative array of the parameters from the browser
By definition its not a json string

Let's assume that the parameter sent by post is json, we can play with that :

$json = $_POST['json'];

Then this should work:

print_r($json);

To get the json as an array, then you should json decode $json, with the true parameter, to get an associative array and not an object

$jsonarray = array();
$jsonarray = json_decode($json, true);

now to print it,foreach is needed:

foreach ($jsonarray as $fieldpost1) {
print_r($fieldpost1);
}

hope that helps

Codeigniter: Pass array of arrays from view to controller

I found the solution to my problem. Here is what worked for me.
I was passing my array of arrays as a string value in a hidden input field using

json_encode($array)

but the problem was that my keys was double quoted and as a result the

value="<?php echo json_encode($array);?>"

was breaking down...

The solution was to escape the characters, so I had to replace the above line with

value="<?php echo htmlspecialchars(json_encode($array));?>"

And in the controller I had to get my array from json with the following lines

$dataJson = $this->input->post('array');
$dataArray = json_decode(htmlspecialchars_decode($dataJson), true);

Thanks everyone for the answers!



Related Topics



Leave a reply



Submit