Re: any examples of using HTML_QuickForm to add users?
| From: | Stowe Spivey | Date: | Thu, 11 Nov 2004 01:04:17 +0000 |
| Subject: | Re: any examples of using HTML_QuickForm to add users? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15432@lists.php.net to get a copy of this message | ||
Here's what I have and it' not checking the unique values. I am
using the example in the documentation.
Any ideas are greatly appreciated!
================================================================
$form->addElement('header', null, 'QuickForm tutorial example');
$form->addElement('text', 'name', 'Enter your name:',
array('size' =>
50, 'maxlength' => 255));
$form->addElement('submit', null, 'Send');
$form->registerRule('checkUnique', 'callback', 'check_unique');
$form->addRule('name', 'Already Taken', 'checkUnique', true);
....
================================================================
this is from the util.php
function check_unique($formvalue) {
// Checks a table in a database, so see if passed value already
exists
// $formvalue = Value you are checking to see if it is unique or not
// connection to db assumedf or this email
$error = "";
// Connect to the mySQL Server
$mysql = mysql_connect($dbhost, $dbuser, $dbpassword);
if(!$mysql)
{
$error = "Cannot connect to Database Host";
return($error);
}
// Open the mySQL Database
$mysqldb = mysql_select_db($db);
if(!$mysqldb)
{
$error = "Cannot open Database";
return($error);
}
// Query Table to see if $formvalue is unique
$myquery = "SELECT * FROM $table WHERE $field = '$formvalue'";
$result = mysql_query($myquery);
if (!$result)
{
$error = "Cannot run Query";
return($error);
}
// Get number of Records found, should be 0 if $formvalue is unique
$unique = mysql_num_rows($result);
if ($unique > 0)
{
$error = $formvalue. " already in use";
return($error);
}
// Return true if $formvalue is unique
return("true");
}
--- Justin Patrin <papercrane@gmail.com> wrote:
> Easy way:
>
> Check when the form is posted and *before* you process it. Output
> the
> error yourself and then display the form as normal.
>
> "Right" way:
>
> Create a function to do this check for you and add it as a
> validation
> callback through QF. Check the addRule documentation.
>
>
> On Wed, 10 Nov 2004 16:33:03 -0800 (PST), Stowe Spivey
> <spiveyspivey@yahoo.com> wrote:
> > I am starting to use HTML_QuickForm and would like to use it for
> > adding users. I can process the user fine and use the form fine.
> >
> > What if in my processing I learn the user name is not unique, how
> do
> > I get that error message back to quickform and redisplay it again
> > with quickform?
> >
> > Many thanks for your ideas!
> >
> > __________________________________
> > Do you Yahoo!?
> > Check out the new Yahoo! Front Page.
> > www.yahoo.com
> >
> > --
> > PEAR General Mailing List (http://pear.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > !DSPAM:4192b4b834961875212667!
> >
> >
>
>
> --
> Justin Patrin
>
__________________________________
Do you Yahoo!?
Check out the new Yahoo! Front Page.
www.yahoo.com