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.

Using filters to allow preset and user-defined donations

  1. LumpySimon
    Member

    I see from this post that it's not curently possible to have a choice of preset and user defined donation amounts out of the box, so I thought maybe I could do it by hooks.

    I've got a multiple choice field 'Donation' (input_1) with £10, £20, £50 and 'other', and I'm using conditional logic to show the 'Your own amount' field (input_2) if 'other' is chosen.

    The problem is the PayPal screen always shows the name of both fields as the item name, which is very confusing. E.g. "Donation, Your own amount" or "£10, Your own amount".

    I thought I could use the gform_pre_submission hook to unset input_1 if it is set to 'other', or to unset input_2 otherwise, but this isn't working:

    add_filter( 'gform_pre_submission_3', 'only_one_donation_field' );
    
    function only_one_donation_field( $form ) {
    
    	if ( isset( $_POST['input_1'] ) and 'other' == $_POST['input_1'] ) {
    		unset( $_POST['input_1'] );
    	} else {
    		unset( $_POST['input_2'] );
    	}
    
    	return $form;
    
    }

    Am I doing something wrong or is this just not possible?

    Many thanks

    Posted 8 years ago on Wednesday April 27, 2011 | Permalink
  2. If you want predefined and USER defined donation (ex. a drop down with predefined values and then the option to enter a user defined value) you can do this using conditional logic.

    - Add a Donation Field and set it as a drop down
    - Add your predefined values for them to choose
    - Make the last option "Other" and leave the price empty (not $0.00 but blank/empty)

    Add another Donation Field to your form and make it a User Defined Price. Select the Advanced tab and use conditional logic to show this field only when the drop down selection in your first Donation Field is set to "Other".

    Now the user can choose from predefined values, or choose Other and enter their own donation value.

    Posted 8 years ago on Wednesday April 27, 2011 | Permalink
  3. Is it possible to use this setup with the main Donation Field as required? It doesn't seem to work. After selecting other, the field is essentially blank on submit and so even though the second user defined field should populate this field, it doesn't or at least doesn't before the validation check.

    Is there a way around that?

    Thanks,
    Jonah

    Posted 8 years ago on Thursday April 28, 2011 | Permalink
  4. It does get tricky in that situation because a blank value is not a valid value and therefore won't pass required field validation. The way around this is you make the Donation field you show when they select Other required. So if they choose Other then the input Donation field is required, if they don't choose Other... then they've already selected a value.

    Since the user input donation field would be hidden by conditional logic if Other isn't selected, it being required isn't going to trigger validation. Only visible required fields will trigger validation.

    Posted 8 years ago on Thursday April 28, 2011 | Permalink
  5. Gotcha, thanks Carl!

    Posted 8 years ago on Thursday April 28, 2011 | Permalink
  6. LumpySimon
    Member

    Hi Carl

    Sorry, maybe my explanation wasn't so clear. The crux of my question is how to use the gform_pre_submission filter to unset a field.

    I have in place exactly what you suggested, (one field called 'donation' and another conditional one called 'your own amount'), but the problem is that the item name shown by PayPal contains the name of both fields, even though only one has been chosen.

    So a visitor who chooses the £10 option sees "£10, Your own amount" as the item. A visitor who chooses 'other', then enters 123.99, sees "Donation, Your own amount".

    What I was trying to do is eliminate the unused field from the data passed to PayPal so the item name is either just "£10" or just "Your own amount".

    Sorry, it's not so easy to describe it! And I'm afraid the site is still in development so not public yet.

    Thanks
    Simon

    Posted 8 years ago on Thursday April 28, 2011 | Permalink
  7. Are you referring to the checkout page in PayPal as far as where they see this?

    Posted 8 years ago on Thursday April 28, 2011 | Permalink
  8. LumpySimon
    Member

    yes that's right: once you click the submit button and are taken to paypal, you see 'purpose', 'amount' and 'total'.

    it's the purpose column that's showing the name of both fields.

    Posted 8 years ago on Thursday April 28, 2011 | Permalink
  9. I was just able to reproduce this issue. It is a bug with the PayPal Add-On, it shouldn't be passing the Donation field if it has an empty price. We will correct this in the next PayPal Add-On release. Until then there isn't a solution to correct this.

    Posted 8 years ago on Thursday April 28, 2011 | Permalink
  10. LumpySimon
    Member

    that's great, thank you very much.

    Posted 8 years ago on Thursday April 28, 2011 | Permalink

This topic has been resolved and has been closed to new replies.