my form is submitting without params in "Customer Information" and "Shipping Information". The form is rendered in a modal and looks like this
#formShipping.modal.fade{"aria-hidden" => "true", "aria-labelledby" => "productShippingLabel", :role => "dialog", :tabindex => "-1"}
.modal-dialog
.modal-content
.modal-header
%button.close{"data-dismiss" => "modal", :type => "button"}
%span{"aria-hidden" => "true"} ×
%span.sr-only Close
%h4#myModalLabel.modal-title Payment Form
.modal-body
/ Button trigger modal
.hide-info
.panel.panel-default
.panel-heading Customer Information
.panel-body
.col-md-3
.col-md-6
%label{:for => "email"} Email Address
%input.form-control{:type => "text"}/
%label{:for => "name"} Name
%input.form-control{:type => "text"}/
%label{:for => "password"} Password
%input.form-control{:type => "text"}/
%label{:for => "password-confirmation"} Password confirmation
%input.form-control{:type => "text"}/
.col-md-3
.panel.panel-default
.panel-heading Shipping Address
.panel-body
.col-md-6
%label{:for => "name"} Name
%input.form-control{:type => "text"}/
%label{:for => "city"} City
%input.form-control{:type => "text"}/
%label{:for => "zipcode"} Zipcode
%input.form-control{:type => "text"}/
.col-md-6
%label{:for => "address"} Address
%input.form-control{:type => "text"}/
%label{:for => "state"} State
%input.form-control{:type => "text"}/
%label{:for => "country"} Country
%input.form-control{:type => "text"}/
.panel.panel-default
.panel-heading
%h3.panel-title Card information
.panel-body
.row
.col-md-6
%label{:for => "name"} Card Number
%input.form-control{:type => "text", "data-stripe" => "number"}/
.col-md-3
%label{:for => "name"} CVC
%input.form-control{:placeholder => "Ex. 331", :type => "text", "data-stripe" => "cvc"}/
.col-md-3
= label_tag :card_month, "Expiration"
= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month", "data-stripe" => "exp-month"}
= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year", "data-stripe" => "exp-year"}
.text-center
%h2.total-amount
Total:
$0.00
%input{:name => "terms", :type => "CHECKBOX"}>/
Agree to terms?
%br/
%br
%span.payment-errors
%input{:name => "store_front", :type => "hidden", :value => #store_front.id}/
.text-center
%button.btn.btn-primary{:type => "submit"} Pay Now!
.modal-footer
%button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Close
My stripe params come through just fine. But this is the result of checking my submitted params:
>> params
=> {"utf8"=>"✓", "authenticity_token"=>"xkgz3HdfwqS0/AfKpQteT1FaJE/LMhMneUKETCug47qhlw=", "order_products"=>[{"product_id"=>"37", "quanity"=>"0"}, {"product_id"=>"38", "quanity"=>"1"}], "switchName1"=>"on", "custom-amount"=>"", "store_front"=>"34", "stripeToken"=>"token", "action"=>"create", "controller"=>"orders"}
Does anyone know why my inputs aren't submitting?
You've forgotten the name attribute for each one of your input elements.
Change:
%input.form-control{:type => "text"}/
to:
%input.form-control{:type => "text", :name =>"email"}/
and set the correct value for each one of your elements.
You have specified you field for lable but not your input so add that
%label{:for => "email"} Email Address
%input.form-control{:email, :type => "text"}/
Related
#tech_data = TagNode.first outputs below object from the controller .
p #tech_data
#<TagNode _id: 5119dcf74054448e576f3392, parent_id: nil, parent_ids: [], name: "categories", path: "categories", _type: "TagNode">
I have a form which has the fields name, _type, and category. But my object doesn't have the field category.
Here's my form
= simple_form_for #tech_data, as: :techtags, :url => view_techtags_technologies_path, :remote => true,:method => :get,:html => {:id => "upsert_techtags",:data => {:spinner => "#tech-ui"}} do |f|
%label.pull-left Type
= f.input :_type, :collection => tech_types, :label => false, :input_html => {:class =>"chzn-select", :data => {:placeholder => "Select Technology Type"}, :multiple => false}
%label.pull-left Name
= f.input :name, :type=>"text", :required => true, :label => false, :placeholder =>"Type the New Technology", :input_html => {:style => "width:265px;margin-bottom:0;"}
%label.pull-left Category
= f.input :category, :collection => [1,2,3,4], :label => false, :input_html => {:class =>"chzn-select", :disabled=>"true",:data => {:placeholder => "Type or select category"}, :multiple => false}
= f.submit "Create", :class => "btn btn-primary pull-right"
My form has an additional field that my object doesn't have. I get an error when the form is loaded, as I don't have category field in my object.
How can I select the category value in the form without adding this field to the model?
You need something like attr_accessor in Ruby,What is attr_accessor in Ruby?
Please include following in your model,which will make to get values from form to controller.
attr_accessor :category
I'm having trouble with a haml form for stripe. I can't get my submit to function. This is my first time building a from wit haml, any input will help. I'm not even sure if my fields are set up correctly to save into the database.
.container
%section#checkout-form
= form_tag("", method: "POST", id: "payment-form") do
.row
#checkout-form.small-8.columns
.row
#name-form.small-12.columns
.row
.small-6.columns
= label_tag :frist_name, "First Name"
= text_field_tag :name => "First Name", :placeholder => "John", :type => "text"
.small-6.columns
= label_tag :Last_Name, "Last Name"
= text_field_tag :name => "Last Name", :placeholder => "Smith", :type => "text"
.row
.small-12.columns
= label_tag :Email, "Email"
= text_field_tag :name => "Email", :placeholder => "test#test.com", :type => "text"
#address-info.small-12.columns
.row
.small-12.columns
= label_tag :Address1, "Address 1"
= text_field_tag :name => "Address1", :placeholder => "123 Street", :type => "text"
.row
.small-12.columns
= label_tag :Address2, "Address 2"
= text_field_tag :name => "Address2", :placeholder => "Apartment/Suite", :type => "text"
.row
.small-6.columns
= label_tag :City, "City"
= text_field_tag :name => "City", :placeholder => "test", :type => "text"
.small-6.columns
= label_tag :State, "State"
= text_field_tag :name => "State", :placeholder => "test", :type => "text"
.row
.small-6.columns
= label_tag :ZIP, "ZIP"
= text_field_tag :name => "ZIP", :placeholder => "64804", :type => "text"
.small-6.columns
= label_tag :Country, 'Country'
= text_field_tag :name => "Country", :placeholder => "USA", :type => "text"
#billing-info.small-12.columns
.row
.small-6.columns
= label_tag :Credit_Card_Number, "Credit Card Number"
= text_field_tag :name => "Credit Card Number", :placeholder => "1234 5678 9055 5555", :type => "text"
.small-3.columns
= label_tag :Month, "Month"
= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month", class: 'minilabel', "data-stripe" => 'exp-month'}
.small-3.columns
= label_tag :Year, "Year"
= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year", "data-stripe" => 'exp-year'}
.row
.small-6.columns
= label_tag :Security_Code, 'Security Code'
= text_field_tag :name => "Security Code", :placeholder => "123", :type => "text"
.small-6.columns
= label_tag :Billing_ZIP, 'Billing ZIP'
= text_field_tag :name => "Billing ZIP", :placeholder => "64804", :type => "text"
/ Form Side
#checkout-info.small-4.columns
/ Info Side
%img#cards-image{:alt => "", :src => image_path("cards.svg")}/
.hr-with-margin
.reward
%h4 $25 Per Month
%h5 21 people
%p text
%a.button.button-green{:href => "#"} Pledge
/ row
.row.pad-top
.small-12.columns
%submit.button.button-green{type: "submit"} Submit Payment
If you are using form_tag for your form, you need to use a submit_tag for your Submit button. It would look like this:
= submit_tag "Submit", :class=> "button button-green"
And make sure that the submit_tag is nested inside of the form_tag.
Also, you are doing the following with your form tag:
= form_tag("", method: "POST", id: "payment-form") do
But you aren't specifying the route that the form is being submitted to. That first parameter is for specifying the route. So you could do something like this:
= form_tag('/users, method: 'POST', id: 'payment-form') do
if you wanted to post to the '/users' route
I have the typical rails _form generated by scaffold for a member model. For the param :state I am using a select tag:
<%= f.select :state, options_for_select(us_states), { :include_blank=>true, :prompt => 'State' }, { :class => 'form-control' } %>
Using a helper method (us states):
def us_states
[
['AK', 'AK'],
['AL', 'AL'], #etc
And for the param "member_since" I am using the select_year helper:
<%= select_year(0, {:start_year => 2013, :end_year => 1920, :field_name => 'member_since', :prompt => 'Choose year', prefix: :member}, {:class => "form-control"} ) %>
Now both of these selects work to create a new record, but neither field is pre-filled in the edit record view. Any thoughts?
<%= f.select :state, us_states, { :include_blank=>true, :prompt => 'State' }, { :class => 'form-control' } %>
and
<%= select_year(f.object.member_since, {:start_year => 2013, :end_year => 1920, :field_name => 'member_since', :prompt => 'Choose year', prefix: :member}, {:class => "form-control"} ) %>
UPDATE:
Since member_since is a string, you will need to convert it to date:
<%= select_year(Date.new(f.object.member_since.to_i), {:start_year => 2013, :end_year => 1920, :field_name => 'member_since', :prompt => 'Choose year', prefix: :member}, {:class => "form-control"} ) %>
I have a bootstrap dropdown menu in my application that is working great, except that when I click on any of the input fields the dropdown menu fades out. I know about the javascript function $('.dropdown-menu').find('form').click(function (e) {
e.stopPropagation();
}); but in my case it doesnt seem to be doing anything.
Here is my code:
%li.dropdown
%a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#"}
Sign In
%span.caret
.dropdown-menu
%form{"accept-charset" => "UTF-8", :action => "/users", :method => "post", :style => "margin: 0px"}
%div{:style => "margin:0;padding:0;display:inline"}
%input{:name => "utf8", :type => "hidden", :value => "✓"}/
%input{:name => "authenticity_token", :type => "hidden", :value => "4L/A2ZMYkhTD3IiNDMTuB/fhPRvyCNGEsaZocUUpw40="}/
%fieldset.textbox{:style => "padding:10px"}
%input{:placeholder => "Username", :style => "margin-top: 8px", :type => "text"}/
%input{:placeholder => "Passsword", :style => "margin-top: 8px", :type => "password"}/
.divider
%input.btn-primary{:name => "commit", :type => "submit", :value => "Log In"}/
Can anyone please point at my error? Why is this not working? Thank is advance.
Try this instead:
$('.dropdown input, .dropdown label').click(function(e) {
e.stopPropagation();
});
I'm sure there has to be a very simple solution to my problem but i don't know why i cant seem to put my finger on it, the problem is that I'm trying to submit a form but every time i submit the form the create action controller gives the following error
Mysql2::Error: Column 'preffered_players' cannot be null: INSERT INTO saved_sessions (preffered_players, session_id, preffered_opponents, game_id, game_type, opponents_list, banned_players, players_list) VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
how ever all these values that the error says are null are passed through parameters as soon as the form is submitted, can anyone tell me how to use the parameter values that i get from the form to fill in the little nulls in my query, create controller is as follow
def create
opponents_list = params[:opponents_list]
banned_players = params[:banned_players]
game_type = params[:game_type]
session_id = params[:session_id]
preffered_opponents = params[:preffered_opponents]
game_id = params[:game_id]
players_list = params[:players_list]
preffered_players = params[:preffered_players]
#saved_sessions = SavedSession.new(params[:saved_sessions])
respond_to do |format|
if #saved_sessions.save
format.html { redirect_to(#game, :notice => 'Game was successfully created.') }
format.xml { render :xml => #game, :status => :created, :location => #game }
else
format.html { render :action => "new" }
format.xml { render :xml => #game.errors, :status => :unprocessable_entity }
end
end
end
thanks for any advice...
i'm including the form code however its very messy(its a huge form) plus its in haml :)
- form_tag('/saved_sessions',:method => :post, :id => "new_game") do
.select_option
.list_col1
.fl
%img{:alt => "image", :border => "0", :src => "/images/happy_face.png"}/
.blue_col
= text_field_tag :preffered_opponents, "", :class => :blue_bar
.clr
.list_col2
.list_col2_top_row
.radio_row
.fl
%input{:type => "radio", :name => "battle_scale", :value => "3"}
.fl 3 vs 3
.fl
%input{:type => "radio", :name => "battle_scale", :value => "5"}
.fl 5 vs 5
.clr
%div
.fl
%img{:alt => "image", :border => "0", :src => "/images/sad_face.png"}/
.fl
/%input#banned_players.white_bar{:type => "text"}/
= text_field_tag :banned_players, "", :class => :white_bar
.clr
.versus_row
#inputs-vs.versus_col1
.versus_col_row
.blue_col
/%input#input-1-vs.blue_bar{:type => "text"}/
= text_field_tag 'input-1-vs', "", :class => :blue_bar
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.clr
.versus_col_row
.blue_col
/%input#input-2-vs.blue_bar{:type => "text"}/
= text_field_tag 'input-2-vs', "", :class => :blue_bar
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.clr
.versus_col_row
.blue_col
/%input#input-3-vs.blue_bar{:type => "text"}/
= text_field_tag 'input-3-vs', "", :class => :blue_bar
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.clr
.versus_col_row
.blue_col
/%input#input-4-vs.blue_bar{:type => "text"}/
= text_field_tag 'input-4-vs', "", :class => :blue_bar
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.clr
.versus_col_row
.blue_col
/%input#input-5-vs.blue_bar{:type => "text"}/
= text_field_tag 'input-5-vs', "", :class => :blue_bar
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.clr
.versus_col2
%img{:alt => "0", :border => "0", :src => "/images/vs.png"}/
#inputs.versus_col1
.versus_col_row
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.blue_col
/%input#input-1.pink_bar{:name => "blah", :type => "text"}/
= text_field_tag 'input-1', "", :class => :pink_bar
.clr
.versus_col_row
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.blue_col
/%input#input-2.pink_bar{:name => "blah", :type => "text"}/
= text_field_tag 'input-2', "", :class => :pink_bar
.clr
.versus_col_row
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.blue_col
/%input#input-3.pink_bar{:name => "blah", :type => "text"}/
= text_field_tag 'input-3', "", :class => :pink_bar
.clr
.versus_col_row
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.blue_col
/%input#input-4.pink_bar{:name => "blah", :type => "text"}/
= text_field_tag 'input-4', "", :class => :pink_bar
.clr
.versus_col_row
.fl
%img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
.blue_col
/%input#input-5.pink_bar{:name => "blah", :type => "text"}/
= text_field_tag 'input-5', "", :class => :pink_bar
.clr
.clr
.session_row
%p
%b You can save and share this session by entering your email. A unique code will be sent
%p.small_text (Session are stored for 30 days)
.seesion_send_row
.fl
/%input.big_white_bar{:type => "text"}/
= text_field_tag 'email_bar', "", :class => :big_white_bar
.fl
%span 2+2=
%span
%span
/%input.small_bar{:type => "text"}/
= text_field_tag 'code_bar', "", :class => :small_bar
.fl
/%a{:href => "#."}
/%img{:alt => "image", :border => "0", :src => "/images/send_button.png"}/
= submit_tag("Send")
hope this can help you guys better understand the problem..
You seem to be pulling from 2 different places. The block of code at the top of the method is pulling the values from the top level of the incoming params, but then later you initialize a new SavedSession using the params[:saved_sessions] input. The two things don't seem to match...
if saved_sessions.opponents_list is found at opponents_list = params[:opponents_list] in the first line, then when you later try to save params[:saved_sessions], you're getting it from a different spot in the params...
EDIT: so you do not need both of the sets of values you have in the action. if you build your form like this (or at least something like this) you'll get the params correctly and can just blindly send them into SavedSession.new, and then call .save.
- form_for(#aved_session) do |f|
-.blue_col
= f.text_field :preffered_opponents, "", :class => :blue_bar
If you allow f.text_field to build the id and name then rails magic will make sure that they are named/id'd correctly and then more rails magic interprets them and builds your input parameters correctly. This will build your params as:
params = {:saved_session => {:preferred_opponents => "text value" }...
Then you can pull those params out:
saved_session_input = params[:saved_session]
and pass them into new just like you are. the difference is that now those parameters are actually IN there.
The way you have it is like this:
params = {:preferred_opponents => "text value", :saved_session => {:preferred_opponents => nil }...
this means you're passing nil in for the expected values for new. Note that you don't actually assign your local values to the new saved_session before calling save.
I hope this is clearer.