Hello all, I''m hoping someone could help me I''m really
getting nowhere
with this.
I have a form that submits info to a mysql database and it seems to
work. The data is submitted but my problem is with the ajax. Once
submitted I''d like the form to disappear and a "success"
message to show
up but I''m having problems. Here is the code from my Sinatra app.
class Contact
include DataMapper::Resource
property :id, Serial
property :full_name, String
property :email, Text
property :subject, Text
property :body, Text
property :date, DateTime
# database.table_exists?(Contact) or database.save(Contact)
end
-----------------------------
And the form response is here:
post ''/'' do
contact=Contact.create(:full_name => params[:fullname], :email =>
params[:email], :subject => params[:subject], :body => params[:message],
:date => Time.now)
redirect (''#/'')
end
-----------------------------
Here is the web form:
<form id="form-1" class="form" method="post"
action="#/">
<div class="form-row">
<div class="label">Name</div>
<div class="input-container"><input
name="fullname" type="text"
class="input req-string" maxlength="40" /></div>
</div>
<div class="form-row">
<div class="label">E-mail</div>
<div class="input-container"><input
name="email" type="text"
class="input req-email" maxlength="100" /></div>
</div>
<div class="form-row">
<div class="label">Subject</div>
<div class="input-container"><input
name="subject" type="text"
class="input" /></div>
</div>
<div class="form-row">
<div class="label">Message</div>
<div class="input-container"><textarea
name="message" cols=""
rows="" class="textarea
req-string"></textarea></div>
</div>
<input id="submitBtn1" type="submit"
class="sendBtn" />
<input name="hid" type="hidden" id="submit"
value="1" />
<div id="errorDiv1" class="error-div"></div>
</form>
-----------------------------
And I have the following javascript validating the form - which works -
but on submit I''d like the form to disappear and a "success"
message to
appear:
<script type="text/javascript"
src="javascripts/jquery.ufvalidator.1.0.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(''#submitBtn1'').formValidator({
//onSuccess : function() { console.log(''Success!''); },
scope : ''#form-1'',
errorDiv : ''#errorDiv1''
});
});
</script>
I''ve tried adding in other code but to no avail. If someone could start
me off int he right direction I''d appreciate it, I''m just not
having any
luck. Really...thanks in advance.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Try returning something other than a redirect. The onSuccess callback will only be executed if the response code is a success (200) and im not sure if it will run the onSuccess when the response is a redirect (300). On Apr 29, 10:57 am, "Dain B." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello all, I''m hoping someone could help me I''m really getting nowhere > with this. > > I have a form that submits info to a mysql database and it seems to > work. The data is submitted but my problem is with the ajax. Once > submitted I''d like the form to disappear and a "success" message to show > up but I''m having problems. Here is the code from my Sinatra app. > > class Contact > include DataMapper::Resource > property :id, Serial > property :full_name, String > property :email, Text > property :subject, Text > property :body, Text > property :date, DateTime > > # database.table_exists?(Contact) or database.save(Contact) > end > ----------------------------- > And the form response is here: > post ''/'' do > contact=Contact.create(:full_name => params[:fullname], :email => > params[:email], :subject => params[:subject], :body => params[:message], > :date => Time.now) > redirect (''#/'') > end > ----------------------------- > > Here is the web form: > > <form id="form-1" class="form" method="post" action="#/"> > <div class="form-row"> > <div class="label">Name</div> > <div class="input-container"><input name="fullname" type="text" > class="input req-string" maxlength="40" /></div> > </div> > <div class="form-row"> > <div class="label">E-mail</div> > <div class="input-container"><input name="email" type="text" > class="input req-email" maxlength="100" /></div> > </div> > <div class="form-row"> > <div class="label">Subject</div> > <div class="input-container"><input name="subject" type="text" > class="input" /></div> > </div> > <div class="form-row"> > <div class="label">Message</div> > <div class="input-container"><textarea name="message" cols="" > rows="" class="textarea req-string"></textarea></div> > </div> > > <input id="submitBtn1" type="submit" class="sendBtn" /> > <input name="hid" type="hidden" id="submit" value="1" /> > <div id="errorDiv1" class="error-div"></div> > </form> > ----------------------------- > > And I have the following javascript validating the form - which works - > but on submit I''d like the form to disappear and a "success" message to > appear: > > <script type="text/javascript" > src="javascripts/jquery.ufvalidator.1.0.1.min.js"></script> > <script type="text/javascript"> > $(document).ready(function(){ > $(''#submitBtn1'').formValidator({ > //onSuccess : function() { console.log(''Success!''); }, > scope : ''#form-1'', > errorDiv : ''#errorDiv1'' > });}); > > </script> > > I''ve tried adding in other code but to no avail. If someone could start > me off int he right direction I''d appreciate it, I''m just not having any > luck. Really...thanks in advance. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hey Kyle, thanks for the tip but that didn''t seem to work. When onSuccess it doesn''t work, nothing happens when I hit the submit button when I use chrome or firefox. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.