Handling Form

0 views
Skip to first unread message

shila romualdo

unread,
Nov 7, 2009, 8:14:42 AM11/7/09
to Philippine Ruby Users Group (PRUG/PhRUG)
Guys,
Im trying to pass a single textfield value from one form to another
form in another page. Every time I hit submit the value disappears as
it goes to the next page.. How would I pass and retrieve the value?
Any help would be great.. Thanks..

Shila

Ramon Tayag

unread,
Nov 7, 2009, 8:29:26 AM11/7/09
to ruby-phil
It should be in the params. Just check your params in your controller,
assign it to a variable or something like that

def new_form
@passed_on_value = params['name_of_that_field']
..
end

then in your view

...
f.text_field :passed_value, :value => @passed_on_value
..

Something like that :)

Ramon Tayag
-
what you think, we ink
http://theinksquad.com



2009/11/7 shila romualdo <shir...@gmail.com>:

shila romualdo

unread,
Nov 7, 2009, 10:48:54 AM11/7/09
to ruby...@googlegroups.com
thanks for the input.. i've tried putting the params in a variable but still when i passed it to the other form the value disappeared.. here are my codes:

view:
<div class="form_row">
            <label for="regnum">Register Num:</label>
           
            <%= form.text_field :regnum, :size => 30, :class => "textInput", :value => @passed %>
           

        </div>

controller:
def edit
@passed = params['regnum']
@something = Something.find_by_reg_number(@passed)   

 
end   

Ramon Tayag

unread,
Nov 7, 2009, 11:35:14 AM11/7/09
to ruby-phil
Try pasting your code in pastie.org - the first form, the controller/s
handling them, then the 2nd form. :)

Ramon Tayag
-
what you think, we ink
http://theinksquad.com

2009/11/7 shila romualdo <shir...@gmail.com>:

Richard Gonzales

unread,
Nov 8, 2009, 10:24:33 AM11/8/09
to ruby...@googlegroups.com
another way is to use sessions.

def controller_action #for the second form
  ...
  if params[:value_from_first_form]
   session[:value_from_first_form] = params[:value_from_first_form]
  end
  ...
end

<%= form.text_field :regnum, :size => 30, :class => "textInput", :value => session[:value_from_first_form] %>

this way, you can check if the passed value has changed, coz if it does, it will change the session's value too
which will be consumed by the next form.

JasonOng

unread,
Nov 11, 2009, 8:08:15 PM11/11/09
to Philippine Ruby Users Group (PRUG/PhRUG)
view:

<% form_for @somthing, :url => edit_something_path(@something) do |f|
%>
<%= form.text_field :reg_number, :size => 30, :class => "textInput"
%>
<% end %>

controller:

def edit
@something = params[:something] ? Something.find_by_reg_number(params
[:something][:reg_num]) : Something.find(params[:id]
end

On Nov 7, 11:48 pm, shila romualdo <shiro...@gmail.com> wrote:
> thanks for the input.. i've tried putting the params in a variable but still
> when i passed it to the other form the value disappeared.. here are my
> codes:
>
> view:
> <div class="form_row">
>             <label for="regnum">Register Num:</label>
>
>             <%= form.text_field :regnum, :size => 30, :class => "textInput",
> :value => @passed %>
>
>         </div>
>
> controller:
> def edit
> @passed = params['regnum']
> @something = Something.find_by_reg_number(@passed)
>
> end
>
> On Sat, Nov 7, 2009 at 9:29 PM, Ramon Tayag <ramon.ta...@gmail.com> wrote:
>
> > It should be in the params. Just check your params in your controller,
> > assign it to a variable or something like that
>
> > def new_form
> >  @passed_on_value = params['name_of_that_field']
> >  ..
> > end
>
> > then in your view
>
> > ...
> > f.text_field :passed_value, :value => @passed_on_value
> > ..
>
> > Something like that :)
>
> > Ramon Tayag
> > -
> > what you think, we ink
> >http://theinksquad.com
>
> > 2009/11/7 shila romualdo <shiro...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages