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.

paypal dynamic options

  1. Hi Guys,

    I'm trying to us the "gform_pre_render" filter to create a dropdown list for a product using the paypal addon.

    If I use the filter, my option list displays correctly, but the paypal add-on no longer works.

    Am I using the wrong filter to accomplish this?

    Thanks

    Posted 13 years ago on Tuesday April 19, 2011 | Permalink
  2. What exactly does not work? Does it trigger a validation error?

    Posted 13 years ago on Tuesday April 19, 2011 | Permalink
  3. There aren't any errors at all. If I override the dropdown (which works fine), it seems to ignore that the form is associated with paypal, and the form will submit like a normal form.

    Here is the function that I'm using....

    add_filter('gform_pre_render_5', 'custom_event_tickets');
    
    function custom_event_tickets($form_meta) {
    	global $sp_ecp;
    	$formId =  $form_meta['id'];
    		$options = sp_get_events('100');
    		//print_r_html ($form_meta);
    		//Creating drop down item array.
    
    		$items = array();
    		//Adding initial blank value.
    		$items[] = array("text" => "Choose...", "value" => "Choose...", "isSelected" => "1", "price"=>'$0.00');
    
     		//Adding Available Events and prices to the items array
    
    		foreach ( $options as $option )
    			{
    				$cost = sp_get_cost($option->ID);
    				if ($cost == "Free") $cost = "$0";
    				$items[] = array("value" => $option->post_title . '... ' .$cost, "text" => $option->post_title . '... ' .$cost, "isSelected" => "", "price" => $cost . ".00" );
    			}
    
    		foreach($form_meta["fields"] as &$field) {
    			if($field["id"] == 1)
            		{
               			$field["type"] = "select";
                		$field["choices"] = $items;
    				}
    		}
    
    		//print_r_html ($form_meta);
    		return $form_meta;
    
    }

    my choices array looks like this before I make the change (this works fine):

    [choices] => Array
                            (
                                [0] => Array
                                    (
                                        [text] =>First Choice
                                        [value] => First Choice
                                        [isSelected] => 1
                                        [price] => $10.00
                                    )
    
                                [1] => Array
                                    (
                                        [text] => Second Choice
                                        [value] => Second Choice
                                        [isSelected] =>
                                        [price] =>$12.00
                                    )
    
                                [2] => Array
                                    (
                                        [text] => Third Choice
                                        [value] => Third Choice
                                        [isSelected] =>
                                        [price] => $15.00
                                    )
    
                            )

    I made sure that my dynamic array showed the same info, the same way, which looks like this:

    [choices] => Array
                            (
                                [0] => Array
                                    (
                                        [text] => Choose...
                                        [value] => Choose...
                                        [isSelected] => 1
                                        [price] => $0.00
                                    )
    
                                [1] => Array
                                    (
                                        [value] => Nathan Angelo... $10
                                        [text] => Nathan Angelo... $10
                                        [isSelected] =>
                                        [price] => $10.00
                                    )
    
                                [2] => Array
                                    (
                                        [value] => Marvin & Leanda King... $0
                                        [text] => Marvin & Leanda King... $0
                                        [isSelected] =>
                                        [price] => $0.00
                                    )
    
                                [3] => Array
                                    (
                                        [value] => Parachute Musical / Mike Mains... $10
                                        [text] => Parachute Musical / Mike Mains... $10
                                        [isSelected] =>
                                        [price] => $10.00
                                    )

    I might easily be overlooking something. I appreciate the help.

    Posted 13 years ago on Tuesday April 19, 2011 | Permalink
  4. It looks like this is an oversight from my part. When determining the fields to be sent to PayPal, a fresh version of the form meta is used without getting run through the gform_pre_render filter. Your new choices are probably getting save as an entry, but the PayPal add-on thinks there aren't any products selected and bypasses the PayPal checkout.
    I will take a deeper look into this and see what I can do to fix it.
    Meanwhile, you can use the gform_paypal_query (http://www.gravityhelp.com/documentation/page/Gform_paypal_query) to manually add your drop down values to the PayPal query. You may need to add a dummy value to your drop down so that the PayPal checkout does not get bypassed.

    Posted 13 years ago on Tuesday April 19, 2011 | Permalink
  5. Thank you very much, I do appreciate it. I will give it a try and let you know my results.

    Posted 13 years ago on Tuesday April 19, 2011 | Permalink
  6. Very cool... thank you! It worked, and all I had to do was use the "gform_paypal_query" filter to update the default query string.

    add_filter('gform_paypal_query_5', 'update_paypal_query');
    function update_paypal_query($query_string) {
        return  $query_string;
    }

    The js for the total field still does not update based on selection ( the js doesn't get called ), but I should hopefully be able to figure that out.

    Thanks again for the help

    Posted 13 years ago on Tuesday April 19, 2011 | Permalink
  7. Great! I am glad that worked for you. Is your drop down a product field or a regular drop down field? The Total calculation should get called if you are using a product field. If you don't figure it out, send a link to your form and I will take a look.

    Posted 13 years ago on Wednesday April 20, 2011 | Permalink
  8. Thank you so much for your help... That was exactly my issue. My $field loop was incorrect, adding the type as "product" and the inputType as "select" fixed all the issues I was having. There is no longer the need to us the gform_paypal_query filter.

    I'll paste the code, just in case this helps anyone else in the future.

    foreach($form_meta["fields"] as &$field) {
    			if($field["id"] == 1)
            		{
               			$field["type"] = "product";
               			$field["inputType"] = "select";
                		       $field["choices"] = $items;
                		     //$field["enablePrice"] = 1;
                             //$field["basePrice"] = '$0.00';
    				}
    			}

    Thanks again!!!

    Posted 13 years ago on Wednesday April 20, 2011 | Permalink

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