Welcome Guest, Not a member yet? Register   Sign In
Date in text field
#1

[eluser]Kemik[/eluser]
Hello,

I know this is a weird question but how do you guys/girls get dates from the user? I'm trying a text field and then storing it in the database (DATE format) however the date isn't saved, just the rest of the query. I've checked all the names to make sure its not a silly mistake but they're all correct.

Fancy taking a look please?

Code:
<?php

$this->validation->set_error_delimiters('<p class="important" style="width: 300px;">', '</p>');
        
$rules['datetime']        = "trim|required|callback_datetime|xss_clean";
$rules['occurs']        = "trim|required|callback_occurs|xss_clean";
$rules['event']         = "trim|required|xss_clean|strip_tags";
        
$this->validation->set_rules($rules);
        
$fields['datetime']        = 'Date';
$fields['occurs']        = 'Occurs';
$fields['event']        = 'Event';
    
$this->validation->set_fields($fields);
        
if ($this->validation->run() == TRUE) {        
            
if ($this->input->post('occurs') == 'one-time') {
            
  $insert = array(
    'date' => $this->input->post('datetime') ,
    'details' => $this->input->post('event')
  );
    
  $this->db->insert('one_events', $insert);
                
  $data['message'] = TRUE;
}
}
?&gt;

The date is validated for dd-mm-yyyy
#2

[eluser]座頭市[/eluser]
Two possibilities come to mind:

1) There's problem with your callback - it might be useful to post the code.

2) If you're using MySQL, the date format should be YYYY-MM-DD, not DD-MM-YYYY
#3

[eluser]Kemik[/eluser]
The callback is good. It doesn't show an error when validating.

The second part might the problem, but even if I ask the user to put it in YYYY-mm-dd format it still doesn't insert Sad
#4

[eluser]Michael Wales[/eluser]
Try inserting it as:
Code:
date('Y-m-d', strtotime($this->input->post('datetime')));




Theme © iAndrew 2016 - Forum software by © MyBB