By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,281 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

self-validating form

P: n/a
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')."'>".($_POS T['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?

Jul 3 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On 3 Jul 2006 11:59:27 -0700, "Mark" <mn*******@gmail.comwrote:
>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.

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?
You might want to look at the approach taken by HTML_QuickForm:

http://pear.php.net/manual/en/packag...m.tutorial.php

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jul 3 '06 #2

P: n/a

Andy Hassall wrote:
On 3 Jul 2006 11:59:27 -0700, "Mark" <mn*******@gmail.comwrote:
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.

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?

You might want to look at the approach taken by HTML_QuickForm:

http://pear.php.net/manual/en/packag...m.tutorial.php

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Wish I could find an example of how it looks printed out.
Looks too bloated though... I don't need all that junk.

Just need some basic checking.

Jul 3 '06 #3

P: n/a
On 3 Jul 2006 12:26:57 -0700, "Mark" <mn*******@gmail.comwrote:
>any ideas how I might fix this problem without overcomplicating my
handy-dandy system?

You might want to look at the approach taken by HTML_QuickForm:

http://pear.php.net/manual/en/packag...m.tutorial.php

Wish I could find an example of how it looks printed out.
Looks too bloated though... I don't need all that junk.

Just need some basic checking.
The basic idea still applies; you need to separate validation from
presentation, so you can check one without doing the other.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jul 3 '06 #4

P: n/a

Andy Hassall wrote:
On 3 Jul 2006 12:26:57 -0700, "Mark" <mn*******@gmail.comwrote:
any ideas how I might fix this problem without overcomplicating my
handy-dandy system?

You might want to look at the approach taken by HTML_QuickForm:

http://pear.php.net/manual/en/packag...m.tutorial.php
Wish I could find an example of how it looks printed out.
Looks too bloated though... I don't need all that junk.

Just need some basic checking.

The basic idea still applies; you need to separate validation from
presentation, so you can check one without doing the other.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Yeah... I guess I figured that. Just didn't want it to have to come to
that... requires so much work.

Now I have to go and learn about PHP objects and stuff like that, so I
can make an array of elements, check em, record their errors, and then
print them w/ errors..

Jul 4 '06 #5

P: n/a
one question; if you redirect a page via header('location:x'); does the
post data get passed along too?

Jul 4 '06 #6

P: n/a
Rik
Mark wrote:
one question; if you redirect a page via header('location:x'); does
the post data get passed along too?
Nope. POST-data is lost AFAIK any kind of redirection.
If you really need that, optiosn are to store POST-data in a session, or to
use CURL

Grtz,
--
Rik Wasmus
Jul 5 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.