How to add an extra submit button to gravity form?
Asked Answered
C

1

1

My site is live and need a bit of customisation to accept PayPal payments along with card payment. It's a non-profit (charity) site.

Some info:

php: 7.4 ; WP: 5.4; theme: Avada 6.2.2; Gravity form: 2.4.17

Site URL: https://www.sevenspikesrelief.org.uk/test/

My question is, how can I add a button at the end of the form for PayPal and get it to do two things:

1- submit the form 2- redirect user to paypal

When I do this using JS (Change the form action when a user clicks PayPal option):

var paypal_radio_input = document.querySelector('#choice_9_16_1');
paypal_radio_input.addEventListener('click', ()=> {
  test_form.action="https://www.paypal.com/gb/fundraiser/charity/2428261";
});

I get redirected to PayPal but all I see is:

We're sorry.

It looks like nothing was found at this location. Maybe try one of the links below or a search?"

And a console error saying:

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'nonce-fYNoVf4KWQbtPUlPUHWImFkshC0qreIuW5C2HMLEKvaOv4J3' 'self' https://*.paypal.com https://*.paypalobjects.com 'unsafe-inline' 'unsafe-eval'". Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.

In case it helps, here is the HTML for the form:

    <form
  method="post"
  enctype="multipart/form-data"
  id="gform_9"
  class="chceckout_form"
  action="/test/"
>
  <div class="gform_heading">
    <h3
      class="gform_title fusion-responsive-typography-calculated"
      data-fontsize="20"
      data-lineheight="30px"
      style="--fontSize:20; line-height: 1.5; --minFontSize:20;"
    >
      Checkout test
    </h3>
    <span class="gform_description"></span>
  </div>
  <div class="validation_error">
    There was a problem with your submission. Errors have been highlighted
    below.
  </div>
  <div class="gform_body">
    <ul
      id="gform_fields_9"
      class="gform_fields top_label form_sublabel_above description_above"
    >
      <li
        id="field_9_5"
        class="gfield gfield_error amount_field gfield_price gfield_price_9_5 gfield_product_9_5 gfield_contains_required field_sublabel_above field_description_above hidden_label gfield_visibility_visible"
      >
        <label class="gfield_label" for="input_9_5"
          >Amount<span class="gfield_required">*</span></label
        >
        <div class="ginput_container ginput_container_product_price">
          <input
            name="input_5"
            id="input_9_5"
            type="text"
            value=""
            class="medium ginput_amount"
            placeholder="Amount"
            aria-required="true"
            aria-invalid="true"
          />
        </div>
        <div
          id="validation_message_9_5"
          class="gfield_description validation_message"
          aria-live="polite"
        >
          This field is required.
        </div>
      </li>
      <li
        id="field_9_16"
        class="gfield payment_method_field gfield_contains_required field_sublabel_above field_description_above gfield_visibility_visible"
      >
        <label class="gfield_label"
          >Payment Method<span class="gfield_required">*</span></label
        >
        <div class="ginput_container ginput_container_radio">
          <ul class="gfield_radio" id="input_9_16">
            <li class="gchoice_9_16_0">
              <input
                name="input_16"
                type="radio"
                value="Card"
                checked="checked"
                id="choice_9_16_0"
              /><label for="choice_9_16_0" id="label_9_16_0">Card</label>
            </li>
            <li class="gchoice_9_16_1">
              <input
                name="input_16"
                type="radio"
                value="Paypal"
                id="choice_9_16_1"
              /><label for="choice_9_16_1" id="label_9_16_1">Paypal</label>
            </li>
          </ul>
        </div>
      </li>
      <li
        id="field_9_4"
        class="gfield card_field field_sublabel_hidden_label field_description_above hidden_label gfield_visibility_visible"
      >
        <label
          class="gfield_label gfield_label_before_complex"
          for="input_9_4_1"
          >Card</label
        >
        <div
          class="ginput_complex ginput_container ginput_container_creditcard"
          id="input_9_4"
        >
          <div class="ginput_full" id="input_9_4_1_container">
            <div id="input_9_4_1"></div>

            <label
              for="input_9_4_1"
              id="input_9_4_1_label"
              class="hidden_sub_label screen-reader-text"
              >Card Details</label
            >
          </div>
          <div class="ginput_full" id="input_9_4_5_container">
            <input
              type="text"
              name="input_4.5"
              id="input_9_4_5"
              value=""
              placeholder="Cardholder Name"
            />
            <label
              for="input_9_4_5"
              id="input_9_4_5_label"
              class="hidden_sub_label screen-reader-text"
              >Cardholder Name</label
            >
          </div>
        </div>
      </li>
      <li
        id="field_9_22"
        class="gfield paypal_note_field gfield_html gfield_html_formatted gfield_no_follows_desc field_sublabel_above field_description_above gfield_visibility_visible"
        style="display: none;"
      >
        You must have a PayPal account to donate via PayPal and you will be
        redirected to our page on PPGF website. JZK
      </li>
      <li
        id="field_9_23"
        class="gfield gfield_html gfield_html_formatted gfield_no_follows_desc field_sublabel_above field_description_above gfield_visibility_visible"
        style="display: none;"
      ></li>
    </ul>
  </div>
  <div class="gform_footer top_label">
    <input
      type="submit"
      id="gform_submit_button_9"
      class="gform_button button"
      value="Donate Now"
      onclick='if(window["gf_submitting_9"]){return false;}  window["gf_submitting_9"]=true;  '
      onkeypress='if( event.keyCode == 13 ){ if(window["gf_submitting_9"]){return false;} window["gf_submitting_9"]=true;  jQuery("#gform_9").trigger("submit",[true]); }'
    />
    <input type="hidden" class="gform_hidden" name="is_submit_9" value="1" />
    <input type="hidden" class="gform_hidden" name="gform_submit" value="9" />

    <input
      type="hidden"
      class="gform_hidden"
      name="gform_unique_id"
      value="5e9d603e301a0"
    />
    <input
      type="hidden"
      class="gform_hidden"
      name="state_9"
      value="WyJbXSIsIjU5NzZiZmEwMGZmOTI0MTM5NWFkNmRhNDQwMGZiMzFhIl0="
    />
    <input
      type="hidden"
      class="gform_hidden"
      name="gform_target_page_number_9"
      id="gform_target_page_number_9"
      value="0"
    />
    <input
      type="hidden"
      class="gform_hidden"
      name="gform_source_page_number_9"
      id="gform_source_page_number_9"
      value="1"
    />
    <input type="hidden" name="gform_field_values" value="" />
  </div>
</form>
Culmiferous answered 19/4, 2020 at 23:30 Comment(4)
The error information you provided "We're sorry. It looks like nothing was found at this location. Maybe try one of the links below or a search?". is not enough to determine what went wrong. Testing the site, there is no submission to PayPal and it just says "There was a problem with your submission. Errors have been highlighted below.", with nothing highlighted.Eberly
@Preston, Sorry i have changed the URL above.Culmiferous
After my discussion with Preston, i came to a point where the form gets submitted and redirection happens but no data is saved on my server woth GET request. any hint please?Culmiferous
The form isn't actually being submitted to your server.. You were submitting the form (POST method) over to PayPal, which is nonsense. You need to submit the form to your server, and PayPal does not accept form posts.Eberly
E
1

The redirect to https://www.paypal.com/gb/fundraiser/charity/2428261 is of type POST, with form data, and it looks like that PayPal page only accepts regular GET page loads

Eberly answered 20/4, 2020 at 6:34 Comment(8)
Thank you fro the reply. i have included the HTML for the form from inspect element.also i have simplified the form for testing purposes. .. however, i'm still unable to solve the issue with the information giving. can you suggest a solution please? appreciated!Culmiferous
I kind of work around it by dynamically changing the method to GET, so now it's redirecting successfully but i have a problem and a question .. the problem is that data entered on frontend (e.g amount) are not saved on submit and the question is : is it still sequre since we are not sending any inforamtion on the GET request ?Culmiferous
You're trying to do two things at once. You need to accomplish the first thing before you do the second thing, and the second thing needs to happen as a discreetly separate step, and not on the client side.Eberly
All i'm doing at the end is submitting the form, data entered are uaually saved on submission. so why isn't the form saving on paypal (get) but still saving on card (post) ?Culmiferous
You are redirecting to PayPal and not posting anything to your server. You need to post to your server.Eberly
hmm, so do you think that there is no way?Culmiferous
Step 1: Post to your server and save the data. Step 2: Once your server has saved the data, redirect the customer to PayPal.Eberly
Let us continue this discussion in chat.Culmiferous

© 2022 - 2024 — McMap. All rights reserved.