Forums

Login form, validation and redirect

lopezio 08 Apr, 2011
Hi
Here is my first work with chronoforms. I need to do the following:
Validate an entry in a Table (named registo) This validation is made with fields email and password. If the user is valid I want to redirect him to one website that is in the field Destino (in the table registo). Here is my code in server side validation

<?php
$email=$_POST['Email'];
$passe=$_POST['Passe'];
$db =& JFactory::getDBO();
$query = "
  SELECT * from registo WHERE Email='$email' and Passe='$passe' 
";
$db->setQuery($query);
if ( $db->loadResult() ) {
 return "You are Registed";
}
?>

Easy, no? But I have one problem who can I get the field Destino in my table?
I try

$segue=db->Destino 

but I had no lucky
After I got the $segue value I only have to do is

header("Location:'$segue'");
GreyHead 09 Apr, 2011
Hi lopezio,

You can do this in serverside validation - but that box is intended for validation and should only 'return' a result if the validation fails.

<?php
$email = JRequest::getString('Email', '', 'post');
$passe = JRequest::getString('Passe', '', 'post');

$db =& JFactory::getDBO();
$query = "
  SELECT `Destino`
    FROM `registo` 
    WHERE `Email` = '$email' AND `Passe` = '$passe'
";
$db->setQuery($query);
$destino = $db->loadResult();
if ( $destino ) {
  global $mainframe;
  $mainframe->redirect($destino);
} else {
  return "You are not Registered";
}
?>
Not tested and will need debugging.

Bob
lopezio 09 Apr, 2011
Hi Greyhead
Thank you for your help but I think the code is not correct. Please look the following

$db->setQuery($query);
$destino = $db->loadResult();
if ( $destino ) {
  global $mainframe;
  $mainframe->redirect($destino);

$destino get's the value 1 (if registed) and we can't redirect to 1.
In this point I need to catch the value of the Field Destino in Table registo (the same table I use to validate the user)
My question is: How can I retrive the value of the field Destino?
Thank you
lopezio 09 Apr, 2011
Found it
Here is the code:

<?php
$email=$_POST['Email'];
$passe=$_POST['Passe'];
$db =& JFactory::getDBO();
$query = "
  SELECT * from registo WHERE Email='$email' and Passe='$passe' 
";
$db->setQuery($query);
$destino = $db->loadResult();
if ( $destino ) {
  global $mainframe;
 $row = $db->loadRow();
 $mainframe->redirect($row[3]);
} else {
  return "You are not Registered";
}
?>
GreyHead 10 Apr, 2011
Hi Lopezio,

Is this now working OK?

Bob
lopezio 10 Apr, 2011
Yes
Work fine, thank you.
lopezio 11 Apr, 2011
Hi
One more point about this question. Is possible to redirect to another chronoform form?
Thank you
GreyHead 11 Apr, 2011
Hi Lopezio,

Yes.

Bob
This topic is locked and no more replies can be posted.