# Problem in form validation of input using onSubmit

**URL:** <https://www.ruby-forum.com/t/problem-in-form-validation-of-input-using-onsubmit/135438>\
**Category:** Rails\
**Created:** [April 22, 2008, 7:34am UTC](https://www.ruby-forum.com/t/problem-in-form-validation-of-input-using-onsubmit/135438 "2008-04-22T07:34:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prionko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5f9b8f/32.png) [@prionko](https://www.ruby-forum.com/u/prionko)\
**Post date:** [April 22, 2008, 7:34am UTC](https://www.ruby-forum.com/t/problem-in-form-validation-of-input-using-onsubmit/135438/1 "2008-04-22T07:34:22Z")

</div>

Hi,  
Im trying to check for uploading of files of only doc and ps types. For  
that matter I have used two javascript funtions and the form. Im trying  
to use onSubmit event handler along with form\_for.But the problem is  
that, files of any types are getting uploaded.  
Can anybody point me out what am I doing wrong here ?

-Thanks  
Saurav

the javascript functions are

the code for form is :

\<%= error\_messages\_for :project %\>

```
  <% form_for :project, :url => {:controller=>:project,:action =>

```

“create”},:html=\>{:multipart =\> true, :name =\> “newproject\_form”,  
:onSubmit =\> “return validate\_form\_fields(this);”} do |f| -%\>

```
  <!--form section-->

      <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>
        <TR>
          <TD HEIGHT=15 COLSPAN=11></TD>
          <TD WIDTH=6 HEIGHT=15></TD>
        </TR>
        <TR>
          <TD width="89" HEIGHT="27">Project Name</TD>
          <TD HEIGHT="27" ><%= f.text_field "name" %></TD>
        </TR>
        <TR>
          <TD HEIGHT=25>Description</TD>
          <TD HEIGHT=25 align="left"><%= f.text_area "description",

```

:cols =\> 40, :rows =\> 10 %\>

  
  
  
Please upload only files that end in: .doc and .ps  

```
        <TR>
        <TD HEIGHT=24>Upload Files </TD>
          <TD HEIGHT=24 ><%= file_field_tag :file1 %></TD>
        </TR>

        <TR>
          <TD height="28" >&nbsp;</TD>
          <TD><a

```

href=“javascript:document.newproject\_form.submit()”;\>

```
          <TD>&nbsp;</TD>
          <TD></TD>
        </TR>
```

---

<div class="post-metadata">

**Author:** ![prionko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5f9b8f/32.png) [@prionko](https://www.ruby-forum.com/u/prionko)\
**Post date:** [April 22, 2008, 9:42am UTC](https://www.ruby-forum.com/t/problem-in-form-validation-of-input-using-onsubmit/135438/2 "2008-04-22T09:42:14Z")

</div>

Hi everybody,  
I have figured it out actually the problem was that the the values were  
not getting passed to the javascript method. Now its working.

Now there is another issue i want to know

instead of tag “Create” in \<%= submit\_tag ‘Create’ %\> can i display some  
image out there so that when i click on the image the form gets  
submitted.

in html i know we can do something like this

\<a href=“javascript:document.newproject\_form.submit()”;\> ![](https://www.ruby-forum.com/images/create.jpg)

Is there any equivalent in erb ??

---

<div class="post-metadata">

**Author:** ![prionko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5f9b8f/32.png) [@prionko](https://www.ruby-forum.com/u/prionko)\
**Post date:** [April 22, 2008, 7:25pm UTC](https://www.ruby-forum.com/t/problem-in-form-validation-of-input-using-onsubmit/135438/3 "2008-04-22T19:25:13Z")

</div>

image\_submit\_tag should do it.

[http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M001046](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M001046)

-Kyle

On Apr 22, 2:42 am, Saurav C. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![prionko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5f9b8f/32.png) [@prionko](https://www.ruby-forum.com/u/prionko)\
**Post date:** [April 23, 2008, 4:44am UTC](https://www.ruby-forum.com/t/problem-in-form-validation-of-input-using-onsubmit/135438/4 "2008-04-23T04:44:59Z")

</div>

Ya I got it yesterday …n now its working fine…nyways thanks for the  
information  
-Saurav  
Kyle wrote:

> image\_submit\_tag should do it.
> 
> [Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M001046)
> 
> -Kyle
> 
> On Apr 22, 2:42 am, Saurav C. \<rails-mailing-l…@andreas-
