[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]
<form view>
Code:
<?php // Change the css classes to suit your needs
$attributes = array('class' => 'remove-bottom', 'id' => 'contactForm');
echo form_open('bookings', $attributes); ?>
<label for="name">Your Name</label> <?php echo form_error('name'); ?>
<input type="text" name="name" id="name" value="<?php echo set_value('name'); ?>" placeholder="Enter name">
<label for="phone">Your Phone Number</label> <?php echo form_error('phone'); ?>
<input type="text" name="phone" id="phone" value="<?php echo set_value('phone'); ?>" placeholder="Enter Phone Number">
<label for="email">Email Address</label> <?php echo form_error('email'); ?>
<input type="text" name="email" id="email" placeholder="Enter email" value="<?php echo set_value('email'); ?>">
<label for="from">From</label>
<input type="text" id="fromDate" name="fromDate" placeholder="Choose From Date" value="<?php echo set_value('fromDate'); ?>"/>
<label for="to">to</label>
<input type="text" id="toDate" name="toDate" placeholder="Enter To Date" value="<?php echo set_value('toDate'); ?>" />
<label for="extras">Extras</label>
<?php echo form_error('extras'); ?>
<textarea rows="5" id="extra" name="extra"><?php echo set_value('extra'); ?></textarea>
<button class="btn btn-success" value="submit">Request Availability!</button>
<?php echo form_close(); ?>