# Newbie question regarding basic AJAX form verification

**URL:** <https://www.ruby-forum.com/t/newbie-question-regarding-basic-ajax-form-verification/53922>\
**Category:** Rails\
**Created:** [February 16, 2006, 11:38pm UTC](https://www.ruby-forum.com/t/newbie-question-regarding-basic-ajax-form-verification/53922 "2006-02-16T23:38:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stan\_McFarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecae2f/32.png) [@Stan\_McFarland](https://www.ruby-forum.com/u/Stan_McFarland)\
**Post date:** [February 16, 2006, 11:38pm UTC](https://www.ruby-forum.com/t/newbie-question-regarding-basic-ajax-form-verification/53922/1 "2006-02-16T23:38:08Z")

</div>

Hi,

I’m confused about how form verification with AJAX works. Let’s say I  
have a  
‘new.rhtml’ view that contains a form with two fields, and the form  
action is  
‘create’. Let’s assume that I also want to do some type of data  
validation on  
one of the two fields via AJAX before I submit the form. But since  
I’ve  
already defined my form action with form\_tag() as ‘create’, I can’t also  
use  
form\_remote\_tag() at the same time, right?

I’m sure I’m missing somethign obvious. but I could use some help.

Thanks,

Stan Mcfarland

---

<div class="post-metadata">

**Author:** ![Stan\_McFarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecae2f/32.png) [@Stan\_McFarland](https://www.ruby-forum.com/u/Stan_McFarland)\
**Post date:** [February 17, 2006, 10:30am UTC](https://www.ruby-forum.com/t/newbie-question-regarding-basic-ajax-form-verification/53922/2 "2006-02-17T10:30:23Z")

</div>

You could do your data validation directly in the method “create” of  
your controller. If data are wrong, just redisplay your form with a  
message error …

Thomas.

---

<div class="post-metadata">

**Author:** ![Stan\_McFarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecae2f/32.png) [@Stan\_McFarland](https://www.ruby-forum.com/u/Stan_McFarland)\
**Post date:** [February 17, 2006, 2:49pm UTC](https://www.ruby-forum.com/t/newbie-question-regarding-basic-ajax-form-verification/53922/3 "2006-02-17T14:49:11Z")

</div>

Thomas \<thomas\_mahier@…\> writes:

> You could do your data validation directly in the method “create” of  
> your controller. If data are wrong, just redisplay your form with a  
> message error …
> 
> Thomas.

Yeah, but that’s not what I need to do. Think, for example, how a spell  
check  
application would work. You have one button to submit the form, and  
another  
button (or link) that does a spell check on a single textarea. This is  
what I  
can’t figure out how to do.

-stan

---

<div class="post-metadata">

**Author:** ![Stan\_McFarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecae2f/32.png) [@Stan\_McFarland](https://www.ruby-forum.com/u/Stan_McFarland)\
**Post date:** [April 4, 2006, 5:32pm UTC](https://www.ruby-forum.com/t/newbie-question-regarding-basic-ajax-form-verification/53922/4 "2006-04-04T17:32:51Z")

</div>

Hi Stan,

I’d have a look at observe\_field.

[http://www.railsmanual.org/module/ActionView::Helpers::PrototypeHelper/observe\_field](http://www.railsmanual.org/module/ActionView::Helpers::PrototypeHelper/observe_field)

There is, as I’m often fond of pointing out, some stuff in Chad F.'s  
Rails Recipes on this. The example is the on-the-fly search (a la  
Google Suggest), but you can use observe\_field to pass the contents of  
an individual field to an action periodically (say once a second) and  
return, say, some RJS to highlight the field red if it doesn’t validate.

observe\_field obviously only works with one field at a time, so I’m not  
sure how you’d pass the whole form periodically.

\<fx: googles around /\>

Oh wait, observe\_form…of course it would be called observe\_form 🙂

[http://www.railsmanual.org/module/ActionView::Helpers::PrototypeHelper/observe\_form](http://www.railsmanual.org/module/ActionView::Helpers::PrototypeHelper/observe_form)

Alan

---

<div class="post-metadata">

**Author:** ![Stan\_McFarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecae2f/32.png) [@Stan\_McFarland](https://www.ruby-forum.com/u/Stan_McFarland)\
**Post date:** [April 4, 2006, 3:08pm UTC](https://www.ruby-forum.com/t/newbie-question-regarding-basic-ajax-form-verification/53922/5 "2006-04-04T15:08:05Z")

</div>

On 2/17/06, Stan McFarland [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yeah, but that’s not what I need to do. Think, for example, how a spell  
> check  
> application would work. You have one button to submit the form, and  
> another  
> button (or link) that does a spell check on a single textarea. This is  
> what I  
> can’t figure out how to do.
> 
> -stan

You can give the spell-check submit button a name, which you can then  
test  
for in @params within your action.

- Rowan
