Hi, I can''t list error_messages in my Form ??, and all the formfields are reset ...(I think my redirect :back clean everything, formfield and error_messages ...), only my flash[:notice] is ok.... I would like to use the "error_messages_for" tag to add a simple red * on my textfiled if a problem occurs ... thanks for help arnaud here are the basics steps to check that password and confirm_password are equal: a form: ----------- <%= form_tag :controller => "contact", :action => "addClient" %> <%= error_messages_for ''client'' %> .... <td><%= text_field "client", "login",:size => 10 %></td> <td><%= password_field "client", "password",:size => 10 %></td> <td><%= password_field "client", "confirm_password",:size => 10 %></td> ... controller: ------------- @client=Person.new(params) if (@client.save) redirect_to :action => "index" else flash[:notice] = "pb during registration !" redirect_to :back end model: --------- I just define a validate method def validate errors.add(:password, "different password ! try again") unless :confirm_password == :password end
Arnaud, Yes the error messages are lost with redirect_to :back. Perhaps you really want to just re-render the form. From your post, I don''t know what action initially renders the form but if it is the "renders_my_form_with_password" action in the same controller then instead of redirect_to :back do render :action=>''renders_my_form_with_password'' -Peter On 7/17/06, Arnaud Garcia <arnaud.garcia@sim.hcuge.ch> wrote:> Hi, > > I can''t list error_messages in my Form ??, and all the formfields are > reset ...(I think my redirect :back clean everything, formfield and > error_messages ...), only my flash[:notice] is ok.... > > I would like to use the "error_messages_for" tag to add a simple red * > on my textfiled if a problem occurs ... > > thanks for help > arnaud > > > here are the basics steps to check that password and confirm_password > are equal: > > a form: > ----------- > <%= form_tag :controller => "contact", :action => "addClient" %> > <%= error_messages_for ''client'' %> > .... > <td><%= text_field "client", "login",:size => 10 %></td> > <td><%= password_field "client", "password",:size => 10 %></td> > <td><%= password_field "client", "confirm_password",:size => 10 %></td> > ... > > controller: > ------------- > @client=Person.new(params) > if (@client.save) > redirect_to :action => "index" > else > flash[:notice] = "pb during registration !" > redirect_to :back > end > > > model: > --------- > I just define a validate method > def validate > errors.add(:password, "different password ! try again") unless > :confirm_password == :password > end > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
many thanks peter, it works render instead of redirect_to ;-) arnaud Peter Michaux a ?crit :> Arnaud, > > Yes the error messages are lost with redirect_to :back. Perhaps you > really want to just re-render the form. From your post, I don''t know > what action initially renders the form but if it is the > "renders_my_form_with_password" action in the same controller then > instead of redirect_to :back do > > render :action=>''renders_my_form_with_password'' > > -Peter > > On 7/17/06, Arnaud Garcia <arnaud.garcia@sim.hcuge.ch> wrote: > >> Hi, >> >> I can''t list error_messages in my Form ??, and all the formfields are >> reset ...(I think my redirect :back clean everything, formfield and >> error_messages ...), only my flash[:notice] is ok.... >> >> I would like to use the "error_messages_for" tag to add a simple red * >> on my textfiled if a problem occurs ... >> >> thanks for help >> arnaud >> >> >> here are the basics steps to check that password and confirm_password >> are equal: >> >> a form: >> ----------- >> <%= form_tag :controller => "contact", :action => "addClient" %> >> <%= error_messages_for ''client'' %> >> .... >> <td><%= text_field "client", "login",:size => 10 %></td> >> <td><%= password_field "client", "password",:size => 10 %></td> >> <td><%= password_field "client", "confirm_password",:size => 10 %></td> >> ... >> >> controller: >> ------------- >> @client=Person.new(params) >> if (@client.save) >> redirect_to :action => "index" >> else >> flash[:notice] = "pb during registration !" >> redirect_to :back >> end >> >> >> model: >> --------- >> I just define a validate method >> def validate >> errors.add(:password, "different password ! try again") unless >> :confirm_password == :password >> end >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >