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

[eluser]Skoobi[/eluser]
Hi im a complete amateur at this but am learning slowly...
Ive been trying to create a online booking form and have come stuck when inserting the date from a jquery datepicker to the mysql database. Im not sure whats going on or how to format it.

Heres my code if anyone could shed some light on it for me. Many thanks

Controller
Code:
// Booking Form Template
    //********************//
    private function _bookings(){

        $this->data['recent_news'] = $this->article_m->get_recent();

        $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('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');
    
        if ($this->form_validation->run() == FALSE) // validation hasn't been passed
        {
            $this->data['recent_news'] = $this->article_m->get_recent();    
        }
        
        else // passed validation proceed to post success logic
        {      
            $this->booking_m->create_booking();
            $this->data['status'] = '<p><strong>Request Sent!!!</strong> We will be in touch shortly.</p>';    
        }
    } // End Booking Form


Model:
Code:
// Frontend Create Booking
public function create_booking()
{
  $data = array(
   'name' => $this->input->post('name'),
   'phone' => $this->input->post('phone'),
   'email' => $this->input->post('email'),
   'fromDate' => $this->input->post('fromDate'),
   'toDate' => $this->input->post('toDate'),
   'extra' => $this->input->post('extra'),
  );
  return $this->db->insert('booking', $data);
}

View:
Script in head:
Code:
[removed]
       $(function() {
               $('#datepicker').datepicker({dateFormat : 'ISO 8601 yy-mm-dd'});
       });
   [removed]

&lt;form view&gt;
Code:
&lt;?php // Change the css classes to suit your needs    

        $attributes = array('class' => 'remove-bottom', 'id' => 'contactForm');
        echo form_open('bookings', $attributes); ?&gt;

        
          <label for="name">Your Name</label> &lt;?php echo form_error('name'); ?&gt;
          &lt;input type="text" name="name" id="name" value="&lt;?php echo set_value('name'); ?&gt;" placeholder="Enter name"&gt;
          
          
          <label for="phone">Your Phone Number</label> &lt;?php echo form_error('phone'); ?&gt;
          &lt;input type="text" name="phone" id="phone" value="&lt;?php echo set_value('phone'); ?&gt;" placeholder="Enter Phone Number"&gt;
          
          
          <label for="email">Email Address</label> &lt;?php echo form_error('email'); ?&gt;
          &lt;input type="text" name="email" id="email" placeholder="Enter email" value="&lt;?php echo set_value('email'); ?&gt;"&gt;
          
          <label for="from">From</label>
          &lt;input type="text" id="fromDate" name="fromDate" placeholder="Choose From Date" value="&lt;?php echo set_value('fromDate'); ?&gt;"/&gt;

          <label for="to">to</label>
          &lt;input type="text" id="toDate" name="toDate" placeholder="Enter To Date" value="&lt;?php echo set_value('toDate'); ?&gt;" /&gt;

          <label for="extras">Extras</label>
          &lt;?php echo form_error('extras'); ?&gt;
          &lt;textarea  rows="5" id="extra" name="extra"&gt;&lt;?php echo set_value('extra'); ?&gt;&lt;/textarea&gt;

          <button class="btn btn-success" value="submit">Request Availability!</button>
        
        

      &lt;?php echo form_close(); ?&gt;


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