Jump to content

[SOLVED] user authentication using quickform


CaptainChainsaw

Recommended Posts

Hi all, I'm using quick form to create my forms and I'm in the process of authenticating users against the database.

 

$form = new HTML_QuickForm('login', 'post');
  $form->addElement('text', 'username', $conf->getConfItem('elementusername'));
  $form->addElement('password', 'password', $conf->getConfItem('elementpassword'));
  $form->addElement('submit', 'btnsubmit', $conf->getConfItem('elementbtnsubmit'));
  $form->registerRule('checkauthusername', 'callback', 'checkforauthusername');
  
  $form->addRule('username', $conf->getConfItem('ruleusernamerequired'), 'required');
  $form->addRule('password', $conf->getConfItem('rulepasswordrequired'), 'required');
  $form->addRule(array('username', 'password'), $conf->getConfItem('rulecheckforauthusername'), 'checkauthusername', $db);
// the last line is the offending line.  I need to pass the username and password
// to my custom validation function so it can go and look up the database to see
// if the username/password combo are correct.  

 

In my custom validation function I have:

 

function checkforauthusername($arr[0], $arr[1], $db){
echo "username = $arr[0], password = $arr[1]";
}

 

I've tried passing them like so too:

 

  $form->addRule('username', 'password', $conf->getConfItem('rulecheckforauthusername'), 'checkauthusername', $db);

 

and also changing the validation function like so:

 

function checkforauthusername($username, $password, $db){
echo "username = $username, password = $password";
}

 

Nothing echoes out to the browser when in checkforauthusername();

 

 

Anyone got any ideas on this one?

 

 

CC :)

Problem solved, was passing array so had to do:

 

function checkforauthusername($array $db){
echo "username = $array[0], password = $array[1]";
}

 

 

and this line for my form:

 

$form->addRule(array('username', 'password'), $conf->getConfItem('rulecheckforauthusername'), 'checkauthusername', $db);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.