Welcome Guest, Not a member yet? Register   Sign In
Datepicker and inserting to DB
#5

[eluser]Skoobi[/eluser]
Many thanks i got it working eventually... with your suggestions.
The one thing im now stuck on is to make it to goto its own controller and then back with the status message. And also pass the data from the form to the database.


Heres my book.php controller which the form now points to

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Book extends CI_Controller {

public function index(){
  
    }


public function makeBooking(){
        $this->load->library('form_validation');
        $this->load->helper('form');  
        $this->load->model('booking_m');  
        $this->form_validation->set_rules('name', 'Name', 'required|trim|xss_clean');      
        $this->form_validation->set_rules('phone', 'Phone Number', 'required|trim|xss_clean');      
        $this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean|valid_email');
        $this->form_validation->set_rules('location', 'Location', 'required|trim|xss_clean');        
        $this->form_validation->set_rules('fromDate', 'From', 'required|trim|xss_clean');
        $this->form_validation->set_rules('toDate', 'To', 'required|trim|xss_clean');
        $this->form_validation->set_rules('extra', 'Extras','trim|xss_clean');

        $this->form_validation->set_error_delimiters('<br /><span class="error">', '</span>');
    
        $data = array(
            'name' => set_value('name'),
            'phone' => set_value('phone'),
            'email' => set_value('email'),
            'location' => set_value('location'),
            'formDate' => set_value('fromDate'),
            'toDate' => set_value('toDate'),
            'extra' => set_value('extra')
        );

        if ($this->form_validation->run() == FALSE) // validation hasn't been passed
        {
            $this->data['status'] = '<p><strong>Something went wrong!</p>';
            redirect('bookings');
        }
        
        else // passed validation proceed to post success logic
        {      
            $this->booking_m->create_booking($data);
            $this->data['status'] = '<p><strong>Request Sent!!!</strong> We will be in touch shortly.</p>';
            redirect('bookings');
        }
    }

}

heres the model booking_m.php
Code:
public function create_booking()
{
  $data = array(
   'name' => $this->input->post('name'),
   'phone' => $this->input->post('phone'),
   'email' => $this->input->post('email'),
   'location' => $this->input->post('location'),
   'fromDate' => $this->input->post('fromDate'),
   'toDate' => $this->input->post('toDate'),
   'extra' => $this->input->post('extra'),
  );
  return $this->db->insert('booking', $data);
}

and i want it to return to the page.php controller and to the method bookings

Code:
private function _bookings(){
        $this->load->library('form_validation');
        $this->load->helper('form');  
        $this->data['recent_news'] = $this->article_m->get_recent();
        
    }


This is probably a simple thing to do for you guys but hey im still learning!!! Im just going through the tuts tutorials now and thats helping a bit.


Messages In This Thread
Datepicker and inserting to DB - by El Forum - 11-21-2013, 03:34 AM
Datepicker and inserting to DB - by El Forum - 11-21-2013, 06:27 AM
Datepicker and inserting to DB - by El Forum - 11-21-2013, 06:32 AM
Datepicker and inserting to DB - by El Forum - 11-21-2013, 10:31 AM
Datepicker and inserting to DB - by El Forum - 11-22-2013, 05:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB