Code Monkey home page Code Monkey logo

Comments (2)

tdumitrescu avatar tdumitrescu commented on June 3, 2024

Thanks for pointing this out. The track_forms() helper is a little bit too simple for your scenario: since it only overrides the form submission event rather than clicks on individual form elements, there's no way to re-submit the form programmatically along with a particular submit input's value (see http://stackoverflow.com/questions/1709301/javascript-submit-does-not-include-submit-button-value for some explanations).

There's a fairly lightweight workaround: use a hidden form field to tell your server which button was pressed, and set its value in a click-handler on your submit buttons. Here's an implementation with ugly inline+global JS (if you use jQuery or other libs, this can be cleaner and unobtrusive):

<input id="submit_type" name="submit_type" type="hidden" value="paid">
<input name="free_sub" value="Free" type="submit" onclick="setSubmitType('free')">
<input name="paid_sub" value="Paid" type="submit" onclick="setSubmitType('paid')">
<script>
    function setSubmitType(stype) {
        document.getElementById('submit_type').value = stype;
    }
</script>

then your server-side check can be something like:

patch :confirm, constraints: lambda {|req| req.params[:submit_type] == 'free'}, action: :free_subscribe
patch :confirm

How do you feel about that approach? In general, particular values from submit inputs are difficult to work with in JS, so people often avoid them for anything except the most straightforward HTML form scenarios.

from mixpanel-js.

Polirecyliente avatar Polirecyliente commented on June 3, 2024

This is also happening to my team. The workaround proposed by @tdumitrescu sadly can't easily work for us, because our code doesn't generate the form, it's generated by an upstream dependency that we are not allowed to patch... as a possible idea for a fix, could Mixpanel save the information about the pressed submit button, and repackage it, maybe as a hidden input to be sent in the POST request?

from mixpanel-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.