Welcome Guest, Not a member yet? Register   Sign In
how to pass array from view to controller
#1

how to pass array from view to controller...please help yaa. Huh
Practice | Practice | Practice
Reply
#2

You don't pass data from a view to a Controller. You pass data from a Controller to a View.

You do pass input data from a form to a controller.
Reply
#3

Do you mean: how to submit a form containing an array, or how to make an ajax request and posting an array, or something else...?
...and then the result will be read by a controller?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#4

(12-31-2015, 07:10 AM)includebeer Wrote: Do you mean: how to submit a form containing an array, or how to make an ajax request and posting an array, or something else...?
...and then the result will be read by a controller?


ya i mean that.
how to pass array on form submition ?
Practice | Practice | Practice
Reply
#5

You need to use multiple input with the same name and [] to tell PHP it's an array. The values will be in $_POST["mytext"].

You can find a simple tutorial here : http://www.sanwebe.com/2013/04/capture-a...-using-php

PHP Code:
<form method="post" action="collect_vals.php">
<
div class="input_fields_wrap">
 
   <button class="add_field_button">Add More Fields</button>
 
   <div><input type="text" name="mytext[]"></div>
 
   <div><input type="text" name="mytext[]"></div>
 
   <div><input type="text" name="mytext[]"></div>
 
   <div><input type="text" name="mytext[]"></div>
 
   <div><input type="text" name="mytext[]"></div>
</
div>
</
form
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#6

(This post was last modified: 09-19-2017, 04:40 AM by olivedev.)

To pass data to view in codeigniter, especially for array, you can do this


PHP Code:
$data = array(
   'title' => 'Title',
   'heading' => 'Heading',
   'message' => ' Message'
);

$this->load->view('cwblogview'$data); 


For multi dimensional array you will have to create loops.

Source: https://www.cloudways.com/blog/how-to-pa...deigniter/
Reply
#7

(12-31-2015, 03:06 AM)Martin7483 Wrote: You don't pass data from a view to a Controller. You pass data from a Controller to a View.

You do pass input data from a form to a controller.


Using Ajax I need to pass an array of data to the controller
Reply
#8

(This post was last modified: 03-28-2019, 05:53 AM by ciadmin.)

Although typically setting the traditional property helps with any time you are passing arrays via AJAX calls, you can still run into issues with serialization. You often need to explicitly set the name of the parameter that you are expecting to populate as seen below :

data: { 'ids': ids },

*SEO link redacted*
Reply




Theme © iAndrew 2016 - Forum software by © MyBB