|
Ryokotsusai -> RE: [PHP] Generic Form Validation Class? (3/29/2008 10:26:44)
|
Sorry for not explaining it clearly (its still before noon XP), This is part of a CMS project, and I would like it to be easy for whoever is operating a this to add custom forms, via a form to create a form, or enter the html directly, and that is where the problem would be. Say I am running a site with this (which i will be eventually) and I have a form I made in, say, FP to replace the standard registration. If I copy and paste this code into the site: <form action="http://www.codeburst.org/?pid=-1&method=full_register" method="post" id="full_register">
<h2>Register a new Account</h2>
<fieldset>
<legend>Account Info</legend>
<p>
<span class="italic red">Required</span>
</p>
<p title="Allowed Characters: A-z 0-9 [] () | : . <> - _ ~ * + =">
<label for="freg_uname">Desired Username:</label>
<input type="text" name="uname" id="freg_uname" maxlength="48" value="" />
</p>
<p>
<label for="freg_email">Email Address:</label>
<input type="text" name="email" id="freg_email" maxlength="48" value="" />
</p>
<p>
<label for="freg_pass1">Password:</label>
<input type="password" name="pass1" id="freg_pass1" maxlength="48" value="" />
</p>
<p>
<label for="freg_pass2">Verify Password:</label>
<input type="password" name="pass2" id="freg_pass2" maxlength="48" value="" />
</p>
</fieldset>
<fieldset>
<legend>Personal Information</legend>
<p>
<span class="italic">Optional</span>
</p>
<p>
<label for="freg_rname">Real Name:</label>
<input type="text" name="rname" id="freg_rname" maxlength="48" value="" />
</p>
<p>
<label for="freg_date">Birth Date:</label>
<input type="text" name="bday" id="freg_date" maxlength="10" value="" />
</p>
<p>
<label for="freg_map">Location:</label>
<input type="text" name="location" id="freg_map" maxlength="48" value="" />
</p>
<p>
<label for="freg_bio">About Me:</label>
<textarea name="bio" cols="30" rows="5" id="freg_bio"></textarea>
</p>
</fieldset>
<p>
<input type="submit" value="Register" class="floatright" />
</p>
</form>
some of that will work as some of the keys are obvious like the key for email fields is 'email'..., but for half of those fields, the validation script will have no idea what they are and will default to *Generic Text Entry* and may flag some of the entered data as invalid... if it helps here is the part of the validation script that decides how to validate the input, and again, this is the only *practical* way i could think of to do this: (its not done yet, i still have to add for radio buttons, selects, etc...) function __construct($array) {
foreach($array as $k => $v) {
if(strpos($k,'email')) {
email($v,$k);
} elseif(strpos($k,'name')) {
name($v,$k);
} elseif(strpos($k,'date')) {
date_($v,$k);
} elseif(strpos($k,'num')) {
num($k,$v);
} else {
gen_text($v,$k);
}
}
}
also this seems like it could be slow for larger forms, so another way would help that too...
|
|
|
|