# Pop up form

**URL:** <https://www.ruby-forum.com/t/pop-up-form/171404>\
**Category:** Rails\
**Created:** [July 1, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/pop-up-form/171404 "2009-07-01T22:51:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![penelope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/53a042/32.png) [@penelope](https://www.ruby-forum.com/u/penelope)\
**Post date:** [July 1, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/pop-up-form/171404/1 "2009-07-01T22:51:37Z")

</div>

I need pop up the pre\_entry form, but I cannot use link\_to because I  
need submit the values to load the Pre-entry form. Anybody have an idea  
to help me?

thanks

view:  
…  
\<%= submit\_tag “Pre-Entry”%\>  
\<%= submit\_tag “Submit”%\>  
[\<%= link\_to “Cancel”, :action =\> “new” %\>]  
…

Controller:  
def submit  
if params[:commit] == “Pre-Entry”  
render :action =\> ‘pre\_entry’  
else  
…

---

<div class="post-metadata">

**Author:** ![penelope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/53a042/32.png) [@penelope](https://www.ruby-forum.com/u/penelope)\
**Post date:** [July 2, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/pop-up-form/171404/2 "2009-07-02T22:51:40Z")

</div>

Penelope W. wrote:

> I need pop up the pre\_entry form, but I cannot use link\_to because I  
> need submit the values to load the Pre-entry form. Anybody have an idea  
> to help me?
> 
> thanks
> 
> view:  
> …  
> \<%= submit\_tag “Pre-Entry”%\>  
> \<%= submit\_tag “Submit”%\>  
> [\<%= link\_to “Cancel”, :action =\> “new” %\>]  
> …
> 
> Controller:  
> def submit  
> if params[:commit] == “Pre-Entry”  
> render :action =\> ‘pre\_entry’  
> else  
> …

Ieeeeeeeeeeeeeee! I found the solution.

view:  
\<%= submit\_to\_popup “Pre-Entry”, :url =\> { :action =\> ‘pre\_entry’ } %\>

applicatio\_helper:

def submit\_to\_popup(label, options = {})  
form\_var = options[:form\_id] ? “$(’#{options[:form\_id]}’)” :  
‘this.form’

```
url = case options[:url]
      when String then options[:url]
      when Hash then url_for options[:url]
      else url_for
      end

button_to_function label, "var 

```

form=#{form\_var};form.action=’#{url}’;form.target=’\_blank’;form.submit();form.action=’#{url\_for}’;form.target=’’;return  
false"  
end

* * *

I hope this can help somebody.
