1

I'm working on a prototype in Rails 3 and ended up using some jquery (my first time and it's pretty sweet). Although, it appears that I am stuck when submitting the data from my view, which is from the Impromptu JQuery Survey, and into a my database (sqllite3). Let me explain how the page works:

  • When a drop down item is selected the survey pops up. Also, this is a modal form and there's about 7 questions.

That's pretty much it. My desired outcome is after the user submits the form by clicking finish, each of the answered questions needs to do into the database. Some of the input fields are checkboxes and dropdowns.

Here is a sample of the code, from the last question of the survey:

state7: {
                    html:'Personality Type <div class="field"><select name="personality" id="rate_find"><option value="enfp">ENFP</option><option value="INTJ">INTJ</option><option value="ESTJ">ESTJ</option><option value="INTP">INTP</option></select></div>',
                    buttons: { Back: -1, Cancel: 0, Finish: 1 },
                    focus: 2,
                    submit: function(v, m, f){
                        if (v == 0) 
                            $.prompt.close()
                        else 
                            if (v == 1) 
                                return true; //we're done
                            else 
                                if (v = -1) 
                                    $.prompt.goToState('state6');//go back
                        return false;
                    }
                }
            }

            $.prompt(temp,{
                callback: function(v,m,f){
                    var str = "You can now process with this given information:<br />";
                    $.each(f,function(i,obj){
                        str += i + " - <em>" + obj + "</em><br />";
                    }); 
                    $.prompt(str)
                }
            });
        }
wolfbagel
  • 319
  • 3
  • 12
  • Not sure what the question is (or what that code is for); if there's a form, it sends parameters--can't you access those? What's the data model look like? – Dave Newton Oct 06 '11 at 22:55
  • So I can use params? I haven't created a model yet, only views and controllers. I guess I was confused as to how I would actually get the values from javascript and pass them. – wolfbagel Oct 06 '11 at 22:58
  • And the code is from the survey modal form. State7 indicates question 7 and the last piece of code writes all the questions to a form at the end. – wolfbagel Oct 06 '11 at 23:00
  • I thought you said you were submitting a form. If you are, there's params--that's where params go. – Dave Newton Oct 06 '11 at 23:00

1 Answers1

0

The key/value pairs containing the information you got through the impromptu popup need to be piled into a POST request like you might expect in a regular form. If you have an ActiveRecord model for the data going into your database, then you could make a form in the view that has the dropdown that triggers the popup, but just make the whole form hidden. Then at the end of your survey you can go through and assign values to the correct input (e.g.

$.each(f,function(i,obj){
     $('input#' + i).val(obj);
});

), and the final 'Finish' button can trigger the submit event on the form. You can look at this question to find out how to check checkboxes with jquery.

Hope that helps!

Community
  • 1
  • 1
Jack
  • 275
  • 1
  • 3
  • 8