format of text string

J

Joop

I'm working on some PHP code that will accept date (yyyy-mm-dd) and
timestamp (yyyy-mm-dd hh:mm:ss) from an HTML form. A plain <input
type="text"> is too simple, my users will get it wrong each time. Now I'm
making separate inputs for the yyyy, mmm etc. parts which is IMO too
unelegant programming when you have to glue it together after the
submission.

Ideal would be something like this:

<input type="text" format="9999-99-99">

Is this possible in HTML 4 without javascript tricks? TIA!
 
D

Default User

Joop said:
I'm working on some PHP code that will accept date (yyyy-mm-dd) and
timestamp (yyyy-mm-dd hh:mm:ss) from an HTML form. A plain <input
type="text"> is too simple, my users will get it wrong each time. Now I'm
making separate inputs for the yyyy, mmm etc. parts which is IMO too
unelegant programming when you have to glue it together after the
submission.


What? Why would simple concatenation in PHP be "inelegant"?

$date = $month."-".$day."-".$year;

That's what scripts are for, to do the donkey work for you and your
users. Nobody sees scripts, nobody cares how elegant they look. The
forms and outputs are what the public has to use, make those sensible
and easy to use. Scripts only need to be correct and efficient.

For proper date formating, it's a good idea to use proper date entries
forms rather than text. That way you don't have to deal with people
putting in month == 42, and having to reject the entry from the script.
Pull-downs for month and day are typical.




Brian Rodenborn
 
R

rf

Joop said:
I'm working on some PHP code that will accept date (yyyy-mm-dd) and
timestamp (yyyy-mm-dd hh:mm:ss) from an HTML form. A plain <input
type="text"> is too simple, my users will get it wrong each time. Now I'm
making separate inputs for the yyyy, mmm etc. parts which is IMO too
unelegant programming when you have to glue it together after the
submission.

So? A little bit of code server side is solving your problem. Why undo that
solution :)
Ideal would be something like this:

<input type="text" format="9999-99-99">

Is this possible in HTML 4 without javascript tricks? TIA!

No.

Cheers
Richard.
 
R

rf

For proper date formating, it's a good idea to use proper date entries
forms rather than text. That way you don't have to deal with people
putting in month == 42, and having to reject the entry from the script.
Pull-downs for month and day are typical.

And a real pain in the arse for the user. I personally hate the things.

Cheers
Richard.
 
D

Default User

rf said:
And a real pain in the arse for the user. I personally hate the things.


Well, that's your opinion, but not mine. Yours may well be the
prevailing opinion, I don't know. Individual text fields with an input
checker will work fine as well.




Brian Rodenborn
 
J

Joop

What? Why would simple concatenation in PHP be "inelegant"?

$date = $month."-".$day."-".$year;

Agreed, that's elegant enough. But my script works a little different than
that. It takes a postgresql table and determines the datatype for each
row. Then it creates the input fields itself, so it's all dynamic. In the
frontend (that's the easy part) it would create 3 inputs for a date, 6 for
a timestamp. The names of the inputs would be something like
fld_yearpart_hiredate, fld_monthpart_hiredate etc.

All this is stuffed into to $_POST array and now comes the ugly part (in
the backend). Normally I parse the $_POST array and create a SQL statement
out of it which I feed to postgresql. But with the date and timestamps
broken up the parsing of the array would be very ugly, because some
elements of it are not complete values, but only parts of a value. I would
have to parse the array with all sorts of checks.

But I guess that's the way to go, seems like HTML can't help me :-(

Thanks anyway for your answers everyone!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top