vinpkl — 2012-10-06T12:11:04-04:00 — #1
To be on safer side i m adding server side validation to my form.
So i would like to know if there is something similar to below "focus" code in php
cups — 2012-10-06T12:57:57-04:00 — #2
Yes - server side validation is mandatory, client side is nice to have.
If you are talking about the form returned to the user, all that PHP can do is send back a stream of html/js which can contain your .focus() instruction so that the required form element lights up or whatever.
You are best off adding a html message as well in case JS is turned off/unavailable.
echo "<p>Please add your name</p>";
echo "<input type=text name=fname id=fname '/>";
That is a simple example of a way of doing it for illustrative purposes, I'm sure you can improve upon it and integrate it.
vinpkl — 2012-10-06T13:06:01-04:00 — #3
thanks for the reply.
i will surely be adding/displaying error messages near the input fields.
i thought it would be better if i could set focus also on the input field through php.
but thats not be possible with php i think ?
cups — 2012-10-06T13:14:23-04:00 — #4
Well, you will have to output some js into the stream of html which includes something like:
vinpkl — 2012-10-06T13:17:34-04:00 — #5
emphacy — 2012-10-06T14:18:35-04:00 — #6
cups — 2012-10-06T16:07:47-04:00 — #7
There is probably a high number of that small number who are visually handicapped and use a screen reader which disables JS.
So, sticking focus on a named form element is a "nice to have", and if you are designing for non-JS enabled readers is not possible so I suggest you accept that think up other ways of bringing it to the attention of the user.