Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

AJAX and SmartyValidate - Redirect Issue

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
cscalzo34
Smarty n00b


Joined: 01 Jun 2007
Posts: 2

PostPosted: Fri Jun 01, 2007 7:02 pm    Post subject: AJAX and SmartyValidate - Redirect Issue Reply with quote

I am a devoted user of SmartyValidate and think its great. I'm starting to write an application using the XAJAX library in PHP - naturally I'd like all of my presentation to be stored in Smarty templates. In addition to that I'm attempting to leverage SmartyValidate. I only have it partially working right now.

I have a form called forgot, which has just one field for a user to enter in their email.

When a user clicks on the forgot password link, the AJAX library displays the forgot password form using the forgot() function below.

Code:
index.server.php
------------------------
function forgot()
{

// register the validator
SmartyValidate::connect($smarty, true);
SmartyValidate::register_validator('email', 'email', 'isEmail', false, false, 'trim');

// show the forgot password form
global $smarty;
$objResponse = new xajaxResponse();
$content = $smarty->fetch('forgot.tpl');
$objResponse->addClear("mainnav","innerHTML");
$objResponse->addClear("bottom","innerHTML");
$objResponse->addAssign("body","innerHTML", $content);
return $objResponse;

}


Code:
forgot.tpl
------------------------

<input name="email" type="text" size="25">
{validate id="email" message="<span class=\"validate\">Please enter in a valid email address</span>"}


When a user clicks on submit, the data is handled by the XAJAX library which packs everything up in to an array like the $_POST global. The function that processes the form is called handleforgot and it takes the form values as arguments.

Code:
function handleforgot($formvalues)
{

   global $smarty;
   $objResponse = new xajaxResponse();

   //validate that we actually got the

   SmartyValidate::connect($smarty);
   if(SmartyValidate::is_valid($formvalues)) {
      // no errors, done with SmartyValidate
      SmartyValidate::disconnect();
      $objResponse->addAlert("This is important information");

   } else {
         // error, redraw the form
      //$smarty->assign($formvalues);
      $content = $smarty->fetch('forgot.tpl');
      //$objResponse->addClear("mainnav","innerHTML");
      //$objResponse->addClear("bottom","innerHTML");
      $objResponse->addAssign("body","innerHTML", $content);
   }
   return $objResponse;
}


SmartyValidate seems to be doing its job just fine. The problem is after it validates the form (correct or incorrect input) it always wants to throw a redirect. Since my application is a single page AJAX app, that doesn't work.

I was wondering if there is any way to suppress this redirect after validation?

Thanks - SmartyValidate is a great plugin. It saves me tons of time and I'd love to use it in this application.
Code:
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Jun 01, 2007 8:24 pm    Post subject: Reply with quote

SmartyValidate doesn't apply any redirects AFAIK.
Back to top
View user's profile Send private message Visit poster's website
cscalzo34
Smarty n00b


Joined: 01 Jun 2007
Posts: 2

PostPosted: Fri Jun 01, 2007 9:00 pm    Post subject: Have it working now Reply with quote

I know what the problem is...I forgot to put "return false;" after the submit button was clicked so it was a client side browser issue.

I have it working now and if anyone is interested I can share example code of SmartyValidate working with xajax.
Back to top
View user's profile Send private message
kayaker411
Smarty n00b


Joined: 17 Jul 2007
Posts: 1

PostPosted: Tue Jul 17, 2007 2:11 am    Post subject: Code example Reply with quote

Hi!

I would like to see the code you wrote for the forgot password form. I've just started using Smarty and am liking it more and more!
Thank you!!

Rich
Back to top
View user's profile Send private message
rola
Smarty n00b


Joined: 04 Jan 2008
Posts: 2

PostPosted: Fri Jan 04, 2008 3:45 am    Post subject: Reply with quote

Hi,thanks cscalzo34, I'm a new memeber here, I think I come right place to study xajax.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP