We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31051
    • 23 Posts
    Hi,

    I want to be able to update certain fields in eForm when the user gives input.
    An example:
    For an orderform, The customer can select an amount of items he wants to order. The price per piece is shown per item.
    Now, if the user fills in an number, the totalprice of that amount of items should be updated on the fly. How can I realize that with eForm ?

    cheers,
    Unforgiven

      • 30711
      • 70 Posts
      I have been trying to figure out the same thing, but I think it’s not possible with eForm. You need javascript, php, ajax or something like that to make it happen. Please post here if you can figure something out.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        There’s two ways you could do this. Have a button "update" that submits the form with the number of items plus whatever else the shopper has filled out. Use eForm’s eFormOnValidate event to hijack eform’s normal validation process, do the calculation, load the fields with the results, and force eForm to reload the form as if it had validation errors (but don’t display any error messages).

        The other way would be with javascript, which while being much nicer does require javascript enabled in the user’s browser. The javascript method wouldn’t even require an "update" button; the field’s onchange javascript event would trigger the calculation and update the cost field.

        To do things right, it should use both methods; the javascript method would hide (or completely remove) the update button, which would function normally if javascript is not enabled in the user’s browser. The eFormValidate code would only run if the update button’s value is being returned, which would only occur if the javascript has not removed it.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org