Posts: 3
Threads: 1
Joined: Sep 2009
Reputation:
0
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.
Posts: 2,456
Threads: 39
Joined: Dec 2008
Reputation:
6
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
Posts: 3
Threads: 1
Joined: Sep 2009
Reputation:
0
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!
Posts: 2,456
Threads: 39
Joined: Dec 2008
Reputation:
6
Sep 22nd, 2009, 12:13 PM
(This post was last modified: Sep 22nd, 2009, 12:14 PM by Ben.)
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
Posts: 3
Threads: 1
Joined: Sep 2009
Reputation:
0
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.
Posts: 1
Threads: 0
Joined: Nov 2009
Reputation:
0
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
|