CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Changing prices in the front end using JavaScript, but new values are not saved
Pages: [1]

Author Topic: Changing prices in the front end using JavaScript, but new values are not saved  (Read 903 times)

lolas

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
    • Freeform Solutions
  • CiviCRM version: Several
  • CMS version: Drupal
  • MySQL version: 5.1+
  • PHP version: Several
Changing prices in the front end using JavaScript, but new values are not saved
October 01, 2013, 02:55:28 pm
Hello Everyone,

I wonder if anyone has any ideas on this problem? On the main contribution page I have modified the price set values using Javascript but the new values are not coming through after form submission? This is necessary for tax stuff since in the Canadian case we need to change the taxes if the billing address province drop down changes.

The JS changes all the hidden inputs that I noticed. For example:
Code: [Select]
<input price="["price_50","229.95||"]" data-amount="229.95" data-currency="CAD" value="100" type="radio" id="CIVICRM_QFID_100_34" name="price_50" checked="checked" class="form-radio"> to
Code: [Select]
<input price="["price_50","210.00||"]" data-amount="210.00" data-currency="CAD" value="100" type="radio" id="CIVICRM_QFID_100_34" name="price_50" checked="checked" class="form-radio">
The JS also updates the total amount.
However after submission the "data-amount" and new total_amount is ignored and the original price is used to set the form _amount field. If I do a dpm on the $form object in postProcess I don't see my values coming through in parameters. $form->_params['price_50'] = 100. (As we might expect)
However there is also $form->_amount which is set to the old value.

I can dive into the code and see where it is getting _amount from in postprocess but I'm hoping I'm missing something more obvious?
Freeform Solutions provides technology and management consulting, website and database development, and managed internet hosting solutions for not-for-profit organizations (NFPs).

lolas

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
    • Freeform Solutions
  • CiviCRM version: Several
  • CMS version: Drupal
  • MySQL version: 5.1+
  • PHP version: Several
Re: Changing prices in the front end using JavaScript, but new values are not saved
October 02, 2013, 02:00:36 pm
Well I had to look into the code to see that it is impossible to do what I would like. The postProcess function uses the option amounts from the priceset in the CRM_Price_BAO_Set::processAmount function.

I would have liked to have the person change the province and see immediate tax changes on the page but I will do a workaround: If they change the country or province it pops up a profile in snippet form. The user is asked to update their address then after submit the contribution page reloads and sets up the correct taxes again.

One more small problem remains: When the profile is submitted from the dialog an alert is shown "Contact Sample TestName has been created". This has to be dismissed before the dialog is closed.
Anyone know how I get rid of the alert? The dialog code is shown below.

(The fail function with the other alert is a placeholder for now)

Code: [Select]
    function my_update_dialog( gid, new_value, old_value ) {
        var dataURL = "/civicrm/profile/edit?reset=1&snippet=5&context=dialog&blockNo=1&prefix=";
        dataURL = dataURL + '&gid=' + gid;
        $.ajax(dataURL)
          .done(function(content) {
                //alert( "success");
                var dia_div = $('#update-billing-dialog-1');
                dia_div.html(content);
                $("#Edit").submit(function() {
                    $(this).closest(".ui-dialog-content").dialog("close");
                });
                dia_div.show().dialog({
                    title: "Update your Billing Country or Province?",
                    modal: true,
                    width: 650,
                    overlay: {
                        opacity: 0.5,
                        background: "black"
                    },
                    close: function( event, ui ) {
                        $('#_qf_Main_upload-bottom').attr("disabled", true);
                        location.reload();
                    }

                });

            }
          )
          .fail(function() {
            alert( "Please visit your user profile to update your Billing address first.");
          });
    }
Freeform Solutions provides technology and management consulting, website and database development, and managed internet hosting solutions for not-for-profit organizations (NFPs).

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Changing prices in the front end using JavaScript, but new values are not saved
October 29, 2013, 11:32:18 am
I think you should probably be glad it's impossible to do what you wanted to originally. Otherwise, your form could get hacked, right? Other than reloading (which seems like a reasonable solution), the only other option would be an ajax refresh of just the form itself.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Changing prices in the front end using JavaScript, but new values are not saved

This forum was archived on 2017-11-26.