FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bypassing a page in a multi-page form
#1
I have a form that I want to give the user the option to either continue to the next page of the form to fill out more information...or skip that part and complete the order.

When I was looking through the params array, I see the submit_button variable but is there a way to add a different submit button? One that routes to one page and one that goes to another form page or the paypal_submit page? (I'm doing PayPal integration here).

Any help is greatly appreciated! Thanks :-)
Reply
#2
oops. posted in wrong thread...can't delete :-(
Reply
#3
Ben,

Do you have any suggestions on how to accomplish this kind of bypassing of a page in a multi-page?
Reply
#4
Oops! Sorry, I missed your post.

Sure! Since you're using the API, you can tell it to redirect to any page you want. Basically, it would work by dynamically constructing the $params to pass to the ft_api_process_form() function.

Here's an example. Pretend the API code at the top of your form page looks like this: (this is the page that you want to redirect to two different locations, depending on the user input)

PHP Code:
<?php
require_once("path/to/form_tools/global/api/api.php");
$fields ft_api_init_form_page("""test");
$params = array(
  
"submit_button" => "submit_button",
  
"next_page" => "next_page.php",
  
"form_data" => $_POST
    
);
ft_api_process_form($params);
?>

So whenever the form on that page is submitted, it will always redirect to next_page.php. What we want to do is choose the location
based on (say) whichever submit button is pressed.

So add the following buttons to your form:

Code:
<input type="submit" name="submit_button" value="Submit! (1)" />
<input type="submit" name="submit_button2" value="Submit! (2)" />

[Note on usability: if the user clicks "enter" on any form field, on many browsers it will pick the FIRST submit button in your form and submit that. So order them in a way that's most logical].

Now, doctor the PHP to figure out which submit button was pressed. If memory serves, it only sends the name-value pair of the submit button that was pressed - not all buttons. So, your PHP could use this info like so:


PHP Code:
<?php
require_once("path/to/form_tools/global/api/api.php");
$fields ft_api_init_form_page("""test");
$params = array(
  
"submit_button" => "submit_button",
  
"next_page" => "next_page.php",
  
"form_data" => $_POST
    
);

// if the user clicked the second button, redirect to a different page
if (isset($_POST["submit_button2"]))
  
$params["next_page"] = "a_different_page.php";

ft_api_process_form($params);
?>

And that's it! If the user clicks the second submit button ("Submit! (2)") they will be redirected to a_different_page.php. Otherwise they get sent to the default ("next_page.php").

I admit, I haven't tested this, but I'm pretty sure it would work fine.

Let me know if you have any trouble or if I didn't explain it very well! Smile

- Ben
Reply
#5
Hey Ben! Thanks for the quick response; I haven't tried yet but I will be tomorrow and I'll let you know if I run into any problems (which I doubt since your solution is very well explained) Smile

Cheers!
Reply
#6
Hmm...it just keeps loading up the page that I'm on if I click the "bypass" button. Perhaps it's because my form has already been initialized? Do I have to include this second submit button in the building of the form phase and not after the database and everything has been setup?
Reply
#7
Yeah keeps reloading the page for me too if I click the submit2 button.
Reply
#8
The following works for me where I wanted to provide the option of either paying via bank or paypal.

PHP Code:
if (isset($_POST['submit2']))
{
  
$params = array(
    
"submit_button" => "submit2",
    
"next_page" => "success_bank.php",
    
"form_data" => $_POST,
        
"finalize" => true
  
);
}
else
{
  
$params = array(
    
"submit_button" => "submit",
    
"next_page" => "paypal_submit.php",
    
"form_data" => $_POST,
  );


Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)