zhiyong
2007-Mar-15 18:55 UTC
How-to: one form, two submit button, two validates-presence_of
Hi, everybody; The following question blocked my way for a couple days. I appreciate any help in advance. I have one form that adds text entry to the database. There are two ways to add the entry: 1. User fills all the fields then click "submit button 1" -- need to validates_presence_of "field-1" and "field-2" 2. User click "submit button 2" -- need to validates_presence_of "field-2" and "field-5". ("field-5" contains a URL and server will search in the internet and fill all other fields automatically) How to implement the validations? Thanks again --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Mar-15 19:23 UTC
Re: How-to: one form, two submit button, two validates-prese
zhiyong wrote:> Hi, everybody; > > The following question blocked my way for a couple days. I appreciate > any help in advance. > > I have one form that adds text entry to the database. There are two > ways to add the entry: > > 1. User fills all the fields then click "submit button 1" -- need to > validates_presence_of "field-1" and "field-2" > > 2. User click "submit button 2" -- need to validates_presence_of > "field-2" and "field-5". ("field-5" contains a URL and server will > search in the internet and fill all other fields automatically) > > How to implement the validations? > > Thanks againvalidates presence takes some options, and one of them you can use is "if", to check which button has been clicked :) -- 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 -~----------~----~----~----~------~----~------~--~---
zhiyong
2007-Mar-15 19:40 UTC
Re: How-to: one form, two submit button, two validates-prese
I have tried the :if option but how to pass the button name to the model? I used params[:create], it doesn''t work On Mar 15, 3:23 pm, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> zhiyong wrote: > > Hi, everybody; > > > The following question blocked my way for a couple days. I appreciate > > any help in advance. > > > I have one form that adds text entry to the database. There are two > > ways to add the entry: > > > 1. User fills all the fields then click "submit button 1" -- need to > > validates_presence_of "field-1" and "field-2" > > > 2. User click "submit button 2" -- need to validates_presence_of > > "field-2" and "field-5". ("field-5" contains a URL and server will > > search in the internet and fill all other fields automatically) > > > How to implement the validations? > > > Thanks again > > validates presence takes some options, and one of them you can use is > "if", to check which button has been clicked :) > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Mar-15 20:37 UTC
Re: How-to: one form, two submit button, two validates-prese
zhiyong wrote:> I have tried the :if option but how to pass the button name to the > model? I used params[:create], it doesn''t work > > On Mar 15, 3:23 pm, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Well in this case you can sent different buttons to different controller but this is another solution. In your case now you should be able to check which button is clicked by using the button name, I think...can you show us your codes? -- 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 -~----------~----~----~----~------~----~------~--~---
zhiyong
2007-Mar-15 21:01 UTC
Re: How-to: one form, two submit button, two validates-prese
here are the several ways I tried in model class: 1. validates_presence_of :label, :tag, :if =>params[:create] ="Create" validates_presence_of :label, :url, :if =>params[:create] ="Get text and save" (it seems that model does not recognize the params[]) 2. validates_presence_of :label, :tag, if => create == "Create" validates_presence_of :label, :url, :if => create == "Get text and save" (no run-time error, but the validation result is not correct) 3. validates_presence_of :label, :tag, if => :create == "Create" validates_presence_of :label, :url, :if => :create == "Get text and save" (same as 2) The "create" is the submit button name and it is not related with the database. I have also written a method in model class, with the validates_presence_of in it, then called from the controller. But the error is that "validates_presence_of" is not a method. it is very strange. On Mar 15, 4:37 pm, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> zhiyong wrote: > > I have tried the :if option but how to pass the button name to the > > model? I used params[:create], it doesn''t work > > > On Mar 15, 3:23 pm, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Well in this case you can sent different buttons to different controller > but this is another solution. > > In your case now you should be able to check which button is clicked by > using the button name, I think...can you show us your codes? > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Mar-16 15:42 UTC
Re: How-to: one form, two submit button, two validates-prese
zhiyong wrote:> here are the several ways I tried in model class: > > 1. validates_presence_of :label, :tag, :if =>params[:create] => "Create" > validates_presence_of :label, :url, :if =>params[:create] => "Get text and save" > (it seems that model does not recognize the params[]) > > 2. validates_presence_of :label, :tag, if => create == "Create" > validates_presence_of :label, :url, :if => create == "Get text > and save" > (no run-time error, but the validation result is not correct) > > 3. validates_presence_of :label, :tag, if => :create == "Create" > validates_presence_of :label, :url, :if => :create == "Get text > and save" > (same as 2) > > The "create" is the submit button name and it is not related with the > database. > > I have also written a method in model class, with the > validates_presence_of in it, then called from the controller. But the > error is that "validates_presence_of" is not a method. it is very > strange. > > > > On Mar 15, 4:37 pm, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>It seems that - the model cannot access the params, so you need to make method in your model to recieve the params from your controller. model def validate(button) do this for that button and do that for that button end controller validate(params[:create]) -- 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 -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Mar-29 21:40 UTC
Re: How-to: one form, two submit button, two validates-prese
zhiyong wrote:> Hi, everybody; > > The following question blocked my way for a couple days. I appreciate > any help in advance. > > I have one form that adds text entry to the database. There are two > ways to add the entry: > > 1. User fills all the fields then click "submit button 1" -- need to > validates_presence_of "field-1" and "field-2" > > 2. User click "submit button 2" -- need to validates_presence_of > "field-2" and "field-5". ("field-5" contains a URL and server will > search in the internet and fill all other fields automatically) > > How to implement the validations? > > Thanks againI''m back to you, while I was working with the validation thing, I wanted to hide some errors if some other is shown. Check if the following input is blank validates_presence_of :nickname, :email, :password Only check the nickname between 4 and 40 IF the nickname is not blank validates_length_of :nickname, :within => 4..40, :if => Proc.new { |u| !u.nickname.blank? } Hope you can use this :) -- 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 -~----------~----~----~----~------~----~------~--~---