0
votes

I am creating a Registration Page and the only issue I am having is that the Date input I have is returning as an Array, which is breaking my SQL request on submission, and I want to be sure that only the date and nothing related to time is being submitted.

The column in my database is labeled DoB and is what the date will be submitted into once the user submits the form. The code:

echo $this->Form->input('DoB', array(
    'label' => 'Date of birth',
    'type' => 'date',
    'dateFormat' => 'YMD',
    'minYear' => date('Y') - 70,
    'maxYear' => date('Y') - 16,
));

I have yet to find and understand it but I believe I could achieve the same result if I were to do a group of the Year Month and Day inputs under the same name of DoB.

EDIT: the values I would like to pass into the column would be formatted as such: YYYY-MM-DD

Demonstration: In other values place test. Leave DoB field as default ('1998', 'May', '7'). Upon submission of form a flash message tells me that there was a fatal error in my SQL where there is no defined Array.

SQL Error: (data columns: "username", "password", "fName", "lName", "DoB") (input from form: "test", "passwordtest", "test", "test", "Array")

2
I would recommend to write your own helper.Moyed Ansari
Please demonstrate the problem - the code in the question will generate a date input, which will automatically be handled on save. There isn't an obvious problem.AD7six
Going by your last edit you've misunderstood what demonstrate means. I meant steps to reproduce including sufficient code for others to see the error, exact error messages, information obtained whilst debugging etc.AD7six
Turned out the problem was I had it in the wrong directory.Gigaratsu

2 Answers

0
votes

you can make normal input to save it to database like ex.

    echo $this->Form->input('begin_time', array(
        'label' => 'Start',
        'value' => date('Y-m-d'). ' 09:00'
    ));

or you can use function like this for ex. in AppModel

    /**
 * input field of type datetime returns array - this func change it 
 * @param array $dateTimeArray
 * @return string "YY-MM-DD HH-ii"
 */
public function timestamp($dateTimeArray) {

    return "{$dateTimeArray['year']}-{$dateTimeArray['month']}-{$dateTimeArray['day']} {$dateTimeArray['hour']}:{$dateTimeArray['min']}";
}

and than in your model in beforeSave use it ;)

0
votes

Don't worry about it anymore. Turned out I had it all in the wrong directory.