# Ajax form in a normal form

**URL:** <https://www.ruby-forum.com/t/ajax-form-in-a-normal-form/160910>\
**Category:** Rails\
**Created:** [February 20, 2009, 9:09pm UTC](https://www.ruby-forum.com/t/ajax-form-in-a-normal-form/160910 "2009-02-20T21:09:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![loader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5daacb/32.png) [@loader](https://www.ruby-forum.com/u/loader)\
**Post date:** [February 20, 2009, 9:09pm UTC](https://www.ruby-forum.com/t/ajax-form-in-a-normal-form/160910/1 "2009-02-20T21:09:50Z")

</div>

Hello everyone!  
Here is my problem. I have a form to create a ticket, and I want to  
upload a file in the same time.  
Basically, a user fill the form and then can attach a file while editing  
his ticket. But what I want to do here, is to send the file during the  
creation of the ticket.

This is the form to create a ticket :

\<% form\_for(@ticket) do |f| %\>

# My first field

\<%= f.label :subject, 'Subject: '%\>  
\<%= f.text\_field :subject, :size =\> 70 %\>

# Submit button

\<%= f.submit “Create” %\>  
\<% end %\>

And I want to add this form (see underneath) into the first form  
(mentioned above). But instead of sending POST data for this second  
form, I’d like to add this variables as hidden fields in the first form.

\<% form\_for(@ticket\_attachment, :html =\> { :multipart =\> true }) do |f|  
%\>

```
<label>File: </label>
<%= file_field(:ticket_attachment, :file) %>

<%= hidden_field :ticket_attachment, :first_thing %>
<%= hidden_field :ticket_attachment, :second_thing %>

<%= f.submit "Upload" %>

```

\<% end %\>

Is that possible?! Maybe with ajax?

Thank you!

---

<div class="post-metadata">

**Author:** ![loader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5daacb/32.png) [@loader](https://www.ruby-forum.com/u/loader)\
**Post date:** [February 21, 2009, 8:04pm UTC](https://www.ruby-forum.com/t/ajax-form-in-a-normal-form/160910/2 "2009-02-21T20:04:25Z")

</div>

You’re going to have problems - AJAX can’t typically access file  
fields (for  
security reasons). Is there any reason that you can’t just add the  
file fields  
directly to the ticket? Maybe with some JS to show/hide them?

–Matt J.

On Feb 20, 3:09 pm, Guillaume L. \<rails-mailing-l…@andreas-
