The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/printthread.php 16 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 909 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1370 fetch_forum_permissions
/printthread.php 76 forum_permissions
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error



Form Tools
jquery form success callback - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1)
+--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5)
+--- Thread: jquery form success callback (/showthread.php?tid=290)



jquery form success callback - robinsonryan - Sep 21st, 2009

This is a tough one and I think I have a work around, but before I code I wanted to bounce this off of people smarter than me.

I want to use the jquery form plugin to submit my form via ajax (http://www.advanced4x4vans.com/form.htm). The truth is, it all works beautifully, except that the form plugin is set up to fire a success callback function. Because formtools redirects users, it sends the form plugin a "302 temporarily moved" response instead of a "200 success". So, the success callback never fires. The response I need is just a short bit of code that says "congrats your form was submitted." So, I might modify the process.php file to check the redirect_url form input for some secret keyword and echo the response. Then I'll get the "200 success" I need, but it seems like a bit of a hack.

If there isn't a way to accomplish what I want, it might be a worthwhile addition to the admin section. A simple checkbox (to acknowledge you just want to output a manually coded response) and a text area containing the response. The text area could contain html, xml, or json data input by the user.

Long post. Sorry. I look forward to any ideas.


RE: jquery form success callback - Ben - Sep 21st, 2009

Hi Ryan,

Interesting problem! Yes, with the built-in processing functions - process.php & the API - you'll get automatically redirected, so you're rather stuck there...

Adding another "special" hidden field to let the process.php script know not to redirect would seem to be the simplest solution from a code point of view, but then that opens up the question about success and error messages. To be really solid, it should output all error messages - not just the success message - and that would be a big undertaking.

Hmm...! I must say, I don't have any terribly brilliant ideas... rats.

That said, I'm not averse to adding in this functionality to the existing code - it may not be the most elegant thing ever, but it will at least solve your case - and other similar situations that people run into. So just do this: on line 323 of process.php, you'll see this:

PHP Code:
if (!empty($form_info["redirect_url"]) || !empty($form_data["form_tools_redirect_url"])) 

change it to this:

PHP Code:
if (isset($form_info["form_tools_no_redirect_success_message"]))
  {
    echo 
$form_info["form_tools_no_redirect_success_message"];
    exit;
  }
  else if (!empty(
$form_info["redirect_url"]) || !empty($form_data["form_tools_redirect_url"])) 

Then, add a new hidden field to your form:

Code:
<input type="hidden" name="form_tools_no_redirect_success_message" value="Congrats your form was submitted" />

That should then work as you described. If this works for you, I'll include it in the next release so you can upgrade in safety.

Sorry I don't have any better solutions for you!

- Ben


RE: jquery form success callback - robinsonryan - Sep 21st, 2009

Thanks for the input Ben. I put some code into the process.php file very similar to what you indicated. There are many other reasons that the solution is not the best, but it will get things done for now. However, even after adding the code, it still isn't firing the success callback and I can't figure out why. I have another form working with the plugin and it performs basicallly an identical task. Send form data to a process.php page and echo some response message. The other form works like a charm. The one that is processed via form tools process.php won't fire the callback.

I'll keep working on it and post what I find out. If I can get it to work, then we can talk about adding something to future releases.

Thanks for the great script!


RE: jquery form success callback - Ben - Sep 22nd, 2009

Bah! Sorry, serves me right for not checking my code.

Try this instead:
PHP Code:
if (isset($form_data["form_tools_no_redirect_success_message"]))
  {
    echo 
$form_data["form_tools_no_redirect_success_message"];
    exit;
  }
  else if (!empty(
$form_info["redirect_url"]) || !empty($form_data["form_tools_redirect_url"])) 

$form_info, $form_data... so close. ;-)

- Ben


RE: jquery form success callback - robinsonryan - Sep 22nd, 2009

In testing, I found that including the response text wasn't robust enough - I can't include the html to display an image for example. So, I came up with a better solution. The code at the end redirects the page, but it could just as easily be an include_once. So, now my hidden form input is called "include". If it is set, the process.php page will do this:

include $redirect_url;

If not, it just behaves normally and does:

header("Location: " . $redirect_url); - the normal behavior.

I can't think of any reason this would cause a problem. I'll post the actual code once I test it a little more. Thanks for the help.


RE: jquery form success callback - sharad - Nov 1st, 2009

Dear Ben,

It will be good if you can add this to FT2. Let the program return a sucess code on successful completion.

Thanks.


(Sep 21st, 2009, 8:08 PM)Ben Wrote: Hi Ryan,

Interesting problem! Yes, with the built-in processing functions - process.php & the API - you'll get automatically redirected, so you're rather stuck there...

Adding another "special" hidden field to let the process.php script know not to redirect would seem to be the simplest solution from a code point of view, but then that opens up the question about success and error messages. To be really solid, it should output all error messages - not just the success message - and that would be a big undertaking.

Hmm...! I must say, I don't have any terribly brilliant ideas... rats.

That said, I'm not averse to adding in this functionality to the existing code - it may not be the most elegant thing ever, but it will at least solve your case - and other similar situations that people run into. So just do this: on line 323 of process.php, you'll see this:

PHP Code:
if (!empty($form_info["redirect_url"]) || !empty($form_data["form_tools_redirect_url"])) 

change it to this:

PHP Code:
if (isset($form_info["form_tools_no_redirect_success_message"]))
  {
    echo 
$form_info["form_tools_no_redirect_success_message"];
    exit;
  }
  else if (!empty(
$form_info["redirect_url"]) || !empty($form_data["form_tools_redirect_url"])) 

Then, add a new hidden field to your form:

Code:
<input type="hidden" name="form_tools_no_redirect_success_message" value="Congrats your form was submitted" />

That should then work as you described. If this works for you, I'll include it in the next release so you can upgrade in safety.

Sorry I don't have any better solutions for you!

- Ben