hi everybody... I have a form_for in that, onclicking submit button i am calling a javascript for validation.If validation fails that form_for doesnt do anything.But even the validation fails it goes to the controller and action. here my code: <%form_for :promotion_code, :url=>{:controller=>"home",:action=>"create",:discount_id=>product.discount.id,:id=>@ad.id} do |f|%> <%=f.radio_button :isemail,"true",:checked=>true%><b>Email </b> <%=f.radio_button :isemail, "false"%><b>Sms</b> <%=f.text_field :email_or_mobile,:size=>20%> <%=f.submit "Generate", :onclick=>"ValidateForm()"%> <%end%> on validation failure it doesn''t go to the :action please help me... -- Posted via http://www.ruby-forum.com/.
You need to move the :onclick => "ValidateForm()" to :onsubmit => "ValidateForm()" in the form_for line. Then when the ValidateForm returns false it will halt submission of the form. You might want to consider using something like this: http://www.livevalidation.com/ There''s a Rails plugin as well: http://github.com/porras/livevalidation/tree/master Cheers, Nicholas On Aug 4, 7:38 am, Md Fisa <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hi everybody... > I have a form_for in that, onclicking submit button i am calling > a javascript for validation.If validation fails that form_for doesnt do > anything.But even the validation fails it goes to the controller and > action. > here my code: > <%form_for :promotion_code, > :url=>{:controller=>"home",:action=>"create",:discount_id=>product.discount .id,:id=>@ad.id} > do |f|%> > <%=f.radio_button :isemail,"true",:checked=>true%><b>Email > </b> > <%=f.radio_button :isemail, "false"%><b>Sms</b> > <%=f.text_field :email_or_mobile,:size=>20%> > <%=f.submit "Generate", :onclick=>"ValidateForm()"%> > <%end%> > > on validation failure it doesn''t go to the :action > > please help me... > -- > Posted viahttp://www.ruby-forum.com/.
On Tue, Aug 4, 2009 at 4:38 AM, Md Fisa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > hi everybody... > I have a form_for in that, onclicking submit button i am calling > a javascript for validation.If validation fails that form_for doesnt do > anything.But even the validation fails it goes to the controller and > action. > here my code: > <%form_for :promotion_code, > :url=>{:controller=>"home",:action=>"create",:discount_id=> > product.discount.id,:id=>@ad.id} > do |f|%> > <%=f.radio_button :isemail,"true",:checked=>true%><b>Email > </b> > <%=f.radio_button :isemail, "false"%><b>Sms</b> > <%=f.text_field :email_or_mobile,:size=>20%> > <%=f.submit "Generate", :onclick=>"ValidateForm()"%> > <%end%> > > on validation failure it doesn''t go to the :action > > please help me...Hi, I think that you really want the onclick handler on the form element instead of the input tag. Then the following should work for you: <%form_for :promotion_code, :url => {:controller=>"home",:action=>"create",:discount_id=> product.discount.id,:id=>@ad.id }, :html => { :onclick => "return ValidateForm();" } do |f|%> <%=f.radio_button :isemail,"true",:checked=>true%><b>Email</b> <%=f.radio_button :isemail, "false"%><b>Sms</b> <%=f.text_field :email_or_mobile,:size=>20%> <%=f.submit "Generate", :onclick=>"ValidateForm()" %> <%end%> Lastly, you can read more on the use of the :html symbol by referring to section 23.5 of AWDwR 3ed. Good luck, -Conrad> > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Aug 4, 2009 at 7:16 AM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Aug 4, 2009 at 4:38 AM, Md Fisa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > > wrote: > >> >> hi everybody... >> I have a form_for in that, onclicking submit button i am calling >> a javascript for validation.If validation fails that form_for doesnt do >> anything.But even the validation fails it goes to the controller and >> action. >> here my code: >> <%form_for :promotion_code, >> :url=>{:controller=>"home",:action=>"create",:discount_id=> >> product.discount.id,:id=>@ad.id} >> do |f|%> >> <%=f.radio_button :isemail,"true",:checked=>true%><b>Email >> </b> >> <%=f.radio_button :isemail, "false"%><b>Sms</b> >> <%=f.text_field :email_or_mobile,:size=>20%> >> <%=f.submit "Generate", :onclick=>"ValidateForm()"%> >> <%end%> >> >> on validation failure it doesn''t go to the :action >> >> please help me... > > > Hi, I think that you really want the onclick handler on the form element > instead of the > input tag. Then the following should work for you: > > <%form_for :promotion_code, > :url => {:controller=>"home",:action=>"create",:discount_id=> > product.discount.id,:id=>@ad.id }, > :html => { :onsubmit => "return ValidateForm();" } do |f|%> > > <%=f.radio_button :isemail,"true",:checked=>true%><b>Email</b> > <%=f.radio_button :isemail, "false"%><b>Sms</b> > <%=f.text_field :email_or_mobile,:size=>20%> > <%=f.submit "Generate" %> > > <%end%> > > Lastly, you can read more on the use of the :html symbol by referring to > section 23.5 of AWDwR 3ed. > > Good luck, > > -Conrad > > >>The correct javascript handler to use would be onsubmit as Nicholas Henry recommends. Thus, the above code has been corrected with this in mind as well as removing the typo. -Conrad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Henry wrote:> You need to move the :onclick => "ValidateForm()" to :onsubmit => > "ValidateForm()" in the form_for line. Then when the ValidateForm > returns false it will halt submission of the form. > > You might want to consider using something like this: > http://www.livevalidation.com/ > > There''s a Rails plugin as well: > http://github.com/porras/livevalidation/tree/master > > Cheers, > NicholasThanks for yor reply .... I applied what you said.But its not getting.When i am giving :onsubmit it doesn''t check for validation.It directly go to the action without doing any validation.When validation return false it shouldn''t execute the action.Your reply appreciated...Thanks verymuch -- Posted via http://www.ruby-forum.com/.
On Tue, Aug 4, 2009 at 9:34 PM, Md Fisa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > Nicholas Henry wrote: > > You need to move the :onclick => "ValidateForm()" to :onsubmit => > > "ValidateForm()" in the form_for line. Then when the ValidateForm > > returns false it will halt submission of the form. > > > > You might want to consider using something like this: > > http://www.livevalidation.com/ > > > > There''s a Rails plugin as well: > > http://github.com/porras/livevalidation/tree/master > > > > Cheers, > > Nicholas > > Thanks for yor reply .... > I applied what you said.But its not getting.When i am giving :onsubmit > it doesn''t check for validation.It directly go to the action without > doing any validation.When validation return false it shouldn''t execute > the action.Your reply appreciated...Thanks verymuch >Hi, please post the Javascript that''s performing the validation? -Conrad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
And please post the form_for code. Thank you. On Wed, Aug 5, 2009 at 3:33 AM, Conrad Taylor<conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Aug 4, 2009 at 9:34 PM, Md Fisa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> >> Nicholas Henry wrote: >> > You need to move the :onclick => "ValidateForm()" to :onsubmit => >> > "ValidateForm()" in the form_for line. Then when the ValidateForm >> > returns false it will halt submission of the form. >> > >> > You might want to consider using something like this: >> > http://www.livevalidation.com/ >> > >> > There''s a Rails plugin as well: >> > http://github.com/porras/livevalidation/tree/master >> > >> > Cheers, >> > Nicholas >> >> Thanks for yor reply .... >> I applied what you said.But its not getting.When i am giving :onsubmit >> it doesn''t check for validation.It directly go to the action without >> doing any validation.When validation return false it shouldn''t execute >> the action.Your reply appreciated...Thanks verymuch > > Hi, please post the Javascript that''s performing the validation? > -Conrad > > > >