self-validating form

This is a discussion on self-validating form within the PHP Language forums, part of the PHP Programming Forums category; so after much searching, and thinking, and pondering and planning, i came up with this most amazing thing, and then ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-03-2006
Mark
 
Posts: n/a
Default self-validating form

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?

Reply With Quote
  #2 (permalink)  
Old 07-03-2006
Andy Hassall
 
Posts: n/a
Default Re: self-validating form

On 3 Jul 2006 11:59:27 -0700, "Mark" <mnbayazit@gmail.com> wrote:

>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 :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Reply With Quote
  #3 (permalink)  
Old 07-03-2006
Mark
 
Posts: n/a
Default Re: self-validating form


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

Reply With Quote
  #4 (permalink)  
Old 07-03-2006
Andy Hassall
 
Posts: n/a
Default Re: self-validating form

On 3 Jul 2006 12:26:57 -0700, "Mark" <mnbayazit@gmail.com> wrote:

>> >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 :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Reply With Quote
  #5 (permalink)  
Old 07-04-2006
Mark
 
Posts: n/a
Default Re: self-validating form


Andy Hassall wrote:
> On 3 Jul 2006 12:26:57 -0700, "Mark" <mnbayazit@gmail.com> wrote:
>
> >> >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 :: andy@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..

Reply With Quote
  #6 (permalink)  
Old 07-05-2006
Mark
 
Posts: n/a
Default Re: self-validating form

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

Reply With Quote
  #7 (permalink)  
Old 07-05-2006
Rik
 
Posts: n/a
Default Re: self-validating form

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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0