Reply to Re: forms + validation

Your name:

Reply:


Posted by panda31 on 09/24/07 15:00

On 24 sep, 16:23, Sergei Riaguzov <he...@world.com> wrote:
> 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?

Hi,

You can also implement an array with critical fields id.
For each critical field, you do your check. In your array, in fact an
associative one with couples key => value, you put key = id and value
= {true or false} according your validation criteria.

Then, when this array is completely filled, for eack id with a false
value, you write "yellow/red/whatever signs".

$critical_items

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация