Posted by Sergei Riaguzov on 09/24/07 14:23
Hi. I haven't written in PHP too much so I think I should ask how my
problem can be solved "the right way".
I'm having some forms (actually this is not my code, and actually I
haven't got it yet but I see the result). This forms should be filled by
user and when filled and when user clickes on the Next button the next
page or the same page with filled results and some yellow/red/whatever
signs that something was not filled is shown.
Now it doesn't do anything of that.
The first thing (showing previously typed values) is simple: I should
just put every field a value from $_POST, like <field value=<?php $_POST
["field"]>.
Now the second one would also be simple, smth like:
function showError(field) {
if (field == NULL)
print "some html element with yellow/red/whatever signs";
}
And now just add this showError() to every field.
But that is not enough because this is not a validation. And if I am to
add validation for every field I have to write as many showError()
functions as there are fields or write a huge switch statement inside
showError().
And if there are some checkboxes, radiobuttons and other select lists
then why should I write all this validation by hand? Maybe there is a way
to specify this validation in more simple way? Like saying that if $_POST
contains information about selection in some list then it should be
selected, and elesewhere it should validate automatically about selection
indices in list and so on.
Is it possible to do such things? Or maybe I should write my showError()
in Javascript instead? Or maybe I am wrong about the solution. What is
the "right way" of doing such things?
[Back to original message]
|