PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Custom form "method" and "action"

  1. Seeing if i can use a Gravity Form to facilitate a credit card payment via a local (South African) payment gateway.

    The biggest stumbling block seems to be the form method and action that should be:

    method="POST" action="https://www.vcs.co.za/vvonline/ccform.asp"

    I looked through the forums, but can't find a definitive answer.
    Your help will be greatly appreciated!

    (Obviously i will have to do some price calculations also - any indication of how far v1.5 is from public release?)

    Posted 14 years ago on Monday November 29, 2010 | Permalink
  2. Yes it is possible to change the form action, however by doing so you lose the built in validation that takes place when a form is submitted. So keep that in mind. The hook to change the form action would be the gform_form_tag hook.

    Here is an example:

    <?php
    add_filter("gform_form_tag", "form_tag", 10, 2);
    function form_tag($form_tag, $form){
    $form_tag = preg_replace("|action='(.*?)'|", "action='custom_handler.php'", $form_tag);
    return $form_tag;
    }
    ?>
    Posted 14 years ago on Monday November 29, 2010 | Permalink
  3. Thanks for this.

    Just need to check if this targets a specific form via ID? If so, where is the ID defined?

    Thanks!!

    Posted 14 years ago on Friday December 3, 2010 | Permalink
  4. I would like to know this also. I'm using the code snippet, but I don't know how to target the form. I have someone working on the custom processing, but I'm responsible to change the form action. Please provide the next steps after the snippet above is in the functions.php file.

    Posted 14 years ago on Friday December 3, 2010 | Permalink
  5. To target a specific form, you can use the following:

    <?php
    add_filter("gform_form_tag", "form_tag", 10, 2);
    function form_tag($form_tag, $form){
       if($form["id'] == 10) //Change 10 to your actual form ID
           $form_tag = preg_replace("|action='(.*?)'|", "action='custom_handler.php'", $form_tag);
    return $form_tag;
    }
    ?>

    You can see your form IDs on the form list page.

    Posted 14 years ago on Friday December 3, 2010 | Permalink
  6. Thanks! That works great.

    add_filter("gform_form_tag", "form_tag", 10, 2);
    function form_tag($form_tag, $form){
    	if($form["id"] == 1){
    		$form_tag = preg_replace("|action='(.*?)'|", "action='http://mydomain.org/custom/process.php'", $form_tag);
    		return $form_tag;
    	}
    }
    Posted 14 years ago on Monday December 6, 2010 | Permalink