• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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?
Test your translation files with Translation Tester
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
Test your translation files with Translation Tester
Reply

#6
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
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.