Welcome Guest, Not a member yet? Register   Sign In
A form with an array of data
#1

[eluser]pdxbenjamin[/eluser]
So i'm pretty sure this is basic stuff...

I have a standard form that works, that has two text input boxes and a submit button, right.
I use ajax to make more fields when a user clicks on a + button. That also works.
This is the input box a user can make as many they wish...
<input type="text" name="calendarStartDate[]" id="start_date" class="textInput" />
I'm making a calendar and these are the text inputs so to add dates.

well, here is where i get stuck and would appreciate some assistance.
How do I get the controller and model to accept the array of dates and put them into a database.


After validation I have this in the controller.

$calendar_id = $_POST['calendar_id'];
$startDates = $_POST['calendarStartDate'];

$cInfo['calendar_id'] = $calendar_id;
$cInfo['start_date'] = $startDates;

The model..
function insert_calendar_date($cInfo)
{
$this->db->insert('calendar_info', $cInfo);
}
#2

[eluser]umefarooq[/eluser]
hi your $startDates is an array you to loop till as element of $startDates to get your values then your controller and model will be like this

Code:
$calendar_id = $_POST[‘calendar_id’];
          $startDates = $_POST[‘calendarStartDate’];

          $cInfo[‘calendar_id’] = $calendar_id;

  function insert_calendar_date($cInfo,$startDates)
  {
      foreach($startDates as $startdate){
      if(!empty($startdate)){
      $cInfo['start_date'] = $startdate;
      $this->db->insert(‘calendar_info’, $cInfo);
      }
     }
  }
try it, i will work




Theme © iAndrew 2016 - Forum software by © MyBB