Default date in hidden input field

Default date in hidden input field

avrrravrrr Posts: 17Questions: 3Answers: 1
edited January 14 in Free community support

Hi

I am trying to implement a date field (named Reg_date in the MySQL database) for Datatables Editor. The problem I am facing is to get this field to, first of all, be hidden, which I achieve by:

type: "hidden",

and secondly to default to the current date, which is done by:

"def": function () {
return new Date();
},

but, seeing that I have the filed type as "hidden", I cannot assign the type as "DateTime" as well, or I simply don't know how to.

Here is my PHP as well:

Field::inst( 'Reg_date' )
->validator('Validate::dateFormat', 'd-m-Y')
->getFormatter('Format::date_sql_to_format', 'd-m-Y')
->setFormatter('Format::date_format_to_sql', 'd-m-Y'),

The field must NOT update when editing a record as this field is used as the registration date for the member.

! This is for an existing database with date fields stored by the client as e.g. 31.08.05 which would translate to 31 Oct 2005.

Replies

  • colincolin Posts: 7,242Questions: 0Answers: 1,222

    If the purpose is to just set the creation time, it would be better to do that on the server as those values can be hacked on the client. On the server, you can use events, see example here.

    Colin

  • avrrravrrr Posts: 17Questions: 3Answers: 1

    Hi Colin

    We have tried this method before but for formatting reasons, the client needs to use mm.dd.yyyy, while MySQL is not allowing us to use datetime for the timestamp. Hence we are left structuring the column as text and having to input the date in said format when creating a new record, which as mentioned must not be updated when editing a record.

  • colincolin Posts: 7,242Questions: 0Answers: 1,222

    and having to input the date in said format when creating a new record

    If the field is hidden there wouldn't be a way for the value to be typed in on the browser. And likewise, if MySQL doesn't like the format you're giving on the server, you can modify that format on the server to be something acceptable.

    Colin

  • avrrravrrr Posts: 17Questions: 3Answers: 1

    Can we maybe populate the field in the form but make it read-only then have a default value?

  • colincolin Posts: 7,242Questions: 0Answers: 1,222

    You can use fields.def to set a default value for a field.

    Colin

  • avrrravrrr Posts: 17Questions: 3Answers: 1

    Hi Colin

    Resolved by the def value and read-only options.

    Thanks!

Sign In or Register to comment.