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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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.. |
|
|||
|
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 |