473,395 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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?

Jul 3 '06 #1
6 2605
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

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
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

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
one question; if you redirect a page via header('location:x'); does the
post data get passed along too?

Jul 4 '06 #6
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marc | last post by:
Hi all, I was using Tkinter.IntVar() to store values from a large list of parts that I pulled from a list. This is the code to initialize the instances: def initVariables(self): self.e =...
15
by: Ralf W. Grosse-Kunstleve | last post by:
****************************************************************************** This posting is also available in HTML format: http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html...
18
by: Ralf W. Grosse-Kunstleve | last post by:
My initial proposal (http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html) didn't exactly get a warm welcome... And Now for Something Completely Different: class autoinit(object):...
4
by: David Coffin | last post by:
I'd like to subclass int to support list access, treating the integer as if it were a list of bits. Assigning bits to particular indices involves changing the value of the integer itself, but...
4
by: marek.rocki | last post by:
First of all, please don't flame me immediately. I did browse archives and didn't see any solution to my problem. Assume I want to add a method to an object at runtime. Yes, to an object, not a...
7
by: Andrew Robert | last post by:
Hi Everyone, I am having a problem with a class and hope you can help. When I try to use the class listed below, I get the statement that self is not defined. test=TriggerMessage(data) var...
24
by: Peter Maas | last post by:
The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version): 1. Instance variables can be easily distinguished from local variables. 2. A method from a particular class can be...
84
by: braver | last post by:
Is there any trick to get rid of having to type the annoying, character-eating "self." prefix everywhere in a class? Sometimes I avoid OO just not to deal with its verbosity. In fact, I try to...
13
by: Kurda Yon | last post by:
Hi, I found one example which defines the addition of two vectors as a method of a class. It looks like that: class Vector: def __add__(self, other): data = for j in range(len(self.data)):...
6
by: Bart Kastermans | last post by:
I am playing with some trees. In one of the procedures I wrote for this I am trying to change self to a different tree. A tree here has four members (val/type/left/right). I found that self = SS...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.