-2

This may be a poorly worded question because I'm not sure of the lingo but allow me to explain.

I have a form field on my website where the user inputs a date (DOB.) I need the date in a specific format (MM-DD-YYYY.)

As of right now, the PHP is able to reject dates not in this specific format. (E. g. M-D-YY or MM/DD/YYYY) It will only accept and store MM-DD-YYYY which is exactly what I want. No problem here.

However, for the sake of making it easier for the user to understand, I would like to add a sort of placeholder inside the field. (E. g. _ - - _ _ _ ) So, as the user is typing those underscores turn into numbers and it skips the hyphens and the user can easily see the date is accurately entered.

March 4, 1982 for example must be 03-04-1982. If the user tries to enter 3-4-1982 what they will actually get with the pre-inserted underscores and hyphens is 34-19-82_ _. The user can easily see this is incorrect.

So, with all that said, the caveat is it MUST be done with PHP (HTML and CSS) only. I know this is possible with javascript but what is required by the webowner is to be javascript free.

Is this possible?

FYI - I am neither the programmer or website owner. I am the translator between them but I am confused what we can do and what we want to do.

**EDIT - Looks like the example of the placeholder text is not showing correctly on my phone. It should be:

underscore underscore hyphen underscore underscore hyphen underscore underscore underscore underscore

David
  • 97
  • 5
  • 3
    This is a javascript related question (Client side) rather than PHP (server side). But there are some plugins (It's generally called "mask input") https://igorescobar.github.io/jQuery-Mask-Plugin/ – Alon Eitan May 05 '16 at 16:10
  • Why not use MySQL's YYYY-mm-dd format? or is that not possible? – Funk Forty Niner May 05 '16 at 16:14
  • To answer the question (I hope/think), sure `placeholder="MM-DD-YYYY"` *n'est-ce pas?* – Funk Forty Niner May 05 '16 at 16:15
  • its not a question of which format to use... it is more of a question of getting the user to input the correct format as specified by the website owner. – David May 05 '16 at 16:16
  • I would advise getting a date-picker plugin (javascript/jQuery) and then configuring that plugin to conform to the date format you require at the server side. – Adam T May 05 '16 at 16:21
  • @David Then this looks to be what you're asking for http://stackoverflow.com/a/13194429/ right? or better yet http://stackoverflow.com/a/2520733/ which stands to be a duplicate here. – Funk Forty Niner May 05 '16 at 16:22
  • HTML5 supports placeholders really well across the board. Are you using HTML5? – Jay Blanchard May 05 '16 at 16:25
  • 1
    Using only PHP? It depends on what that mean. You often use PHP to generate code in other languages (HTML, CSS, JavaScript) so that means "yes" but of course it's not PHP the one that does the real job. – Álvaro González May 05 '16 at 16:28
  • as stated, javascript is not an option. please read the entire post. the website owner does not want javascript. so, it cant be a javascript plug in and this cant be a javascript question. there is no javascript on the entire site and will not be any. – David May 09 '16 at 02:32
  • less to do with date format, more to do with having placeholder text inside a field. as to prompt the user what to insert. – David May 09 '16 at 02:41
  • i think left date out of it. every one sees date and just assumes that it is about date. see the question doesnt even contain the word date? – David May 09 '16 at 02:43

1 Answers1

0

i think is not possible !

please see this link :

Is there any way to change input type=“date” format?

Community
  • 1
  • 1
Think Big
  • 1,021
  • 14
  • 24
  • Yes it is possible in PHP. – Funk Forty Niner May 05 '16 at 16:23
  • 2
    this should be a comment, not an answer – Pevara May 05 '16 at 16:27
  • in php ok (send to server and validation)! but Mr.David want one thing like input mask with HTML and CSS ! is it possible without using a script language such as Js? – Think Big May 05 '16 at 16:30
  • no, this is not what i am looking for. i am looking for a way to have text already in the field as a guide for user input. i need the user to input the correct format as specified by the Web designer. – David May 09 '16 at 02:26
  • we already have the site in mm-dd-YYYY format... the website will reject anything not in this format. however, the user needs to be guided or prompted to enter it that way or else the user will continuously get an error message "please enter in the correct format mm-dd-YYYY. the website already and only accpets mm-dd-YYYY. its already programed for mm-dd-YYYY. this question is not answered. – David May 09 '16 at 02:37
  • David we have two validation : – Think Big May 09 '16 at 19:06
  • 1- server validation such as php and etc..., 2 - client validation such as javascript , HTML. now Which method do you use? – Think Big May 09 '16 at 19:11