You are here: self-validating form « PHP Programming Language « IT news, forums, messages
self-validating form

Posted by Mark on 07/03/06 18:59

so after much searching, and thinking, and pondering and planning, i
came up with this most amazing thing, and then realized one major flaw
which i was hoping you guys might help me overcome.

first, we have the magic form.

<?php
function input($label,$name,$type,$min=0) {
return "<div
class='".($min?($_POST['submit']&&strlen($_POST[$name])<$min?'error':'required'):'optional')."'>".($_POST['submit']
&& strlen($_POST[$name])<$min ? (empty($_POST[$name]) ?
'<span>Required.</span>' : '<span>Too short.</span>') : '')."<label
for='$name'>$label</label><input type='$type' class='$type'
name='$name' id='$name'
value='".stripslashes(htmlspecialchars($_POST[$name],ENT_QUOTES))."'
/></div>\n";
}
?>
<form method='post' action='<?=$_SERVER['REQUEST_URI']?>'>
<fieldset><legend>Registration Information</legend>
<?=input('Username','user', 'text', 3)?>
<?=input('Password','pass', 'password', 6)?>
<?=input('Confirm password','pass2', 'password', 6)?>
</fieldset>
<fieldset><legend>Profile Information</legend>
<?=input('Personal e-mail','email', 'text')?>
<?=input('MSN messenger','msnm', 'text')?>
</fieldset>
<input type='submit' class='submit' name='submit' id='submit'
value='Submit'>
</form>

it creates a pretty little form, with labels and names and id's for
styling to your heart's content, and better yet, you can add a "minimum
length" parameter, and when you hit submit it'll spit out a little
error if you screwed something up.

sample viewable here: http://xailus.com/files/form_sample.gif

now this is very nice and all, but it occured to me that if a user does
actually manage to fill in a simple form.. it won't be until after the
form re-rendered that I will be able to determine that there were no
errors, since it does the error checking and form-creation at the same
time.

any ideas how I might fix this problem without overcomplicating my
handy-dandy system?

 

Navigation:

[Reply to this 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

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