Re: How to make a simple Contact Form

Re: How to make a simple Contact Form

Hi,

I made my contact form according to this tutorial posted by dawie, and it works very reliably. However, it is far too complicated in the long run because it makes me create additional models just to get the benefit of ActiveRecord's validation features.

I think this is probably the simplest way to create a working contact form for your website.However, it does no validation whatsoever, so users can easily send you empty messages by mistake.

I am currently trying to implement "real-time validation" using Ajax, but have no idea where to start. I want the form field to get validated before the user even hits the submit button. How can I achieve this effect?Can anybody hint me into the right direction?

Re: How to make a simple Contact Form

Hi there,I have tried all the above examples in both testing an in production environments. the one that seemed to make the most sense to me was pb hogans 'tableless' valid contact form, that dawie linked to.I have it running w/ out error and have tested it both locally and on live servers and am constantly having the same problem. when the submit button is hit the correct running but the form just reloads no success or failure message, no email is sent.I am lost and getting ready to just connect to a php from via the rails controller.totally confused and pretty ready to throw in the rails towel.

JOsh

since, forum sigs are a good way to have a soap box, here I go.A BBCode WYSIWYG would be a great addition to this site.

Re: How to make a simple Contact Form

Hi Josh,Sorry, I haven't got a clou here. All I can say is that the code in my previous post (the one above yours) works perfectly fine. You can see it in action on my Website. On my website I am using some Ajax validation techniques, that aren't included in the code above. In one of my previous projects I followed the tutorial you mention and it still works great. You can see it here: Link

Re: How to make a simple Contact Form

Ok well here is my code as well as a snippet of the log file, of the rendering of the code. forgive me now for my repetitiveness as some of this is direct cut and paste. (maybe that is my problem). any one got any clues as to why this is happening?

Re: How to make a simple Contact Form

Hi sanguis,

I spent some time trying to figure out what may be wrong in your code, but to be honest with you I can't see any reason why it should not work. I got into programming only about a year ago, so it's hard for me to give you any advice. All I can say is that I followed the exact same tutorial and it worked great for me.

Re: How to make a simple Contact Form

Status update. progress made.I commented out the rescue options in the controller and am not getting 'proper' in my log files. I can finally start to route out the problems I have been having. they actually don't stem from the contact form code but, part of the template (or theme) manager causing the problem.

any one got any suggestions on how I tell a mailer that it does note need a theme?btw the theme contoler is part of the CMS, Eribium.

Re: How to make a simple Contact Form

If you are looking for a good javascript form validation script check out YAV. I am currently using it in a project and it works great. It also has good documentation and shows working examples to help you get it up and running quickly.http://yav.sourceforge.net/en/index.html

Re: How to make a simple Contact Form

I just tried the tableless solution proposed in this thread. It wasnt working at all so I commented out the rescue statement in the controller and following the stack trace I see that the error is in the send_contact_request action.

undefined method `contact_message'

Now to me this makes no sense, because in my entire project, there is no call to this method. The only thing that comes close would be this.

Mailer::deliver_contact_message(@contact)

All problems aside, I am pretty disappointed with how complicated it is to make a simple contact form in Rails. This task is much easier in PHP.

this is all IN THE MODEL, you might expect it to be in a controller for wahtever reason but it's not, mailers don't usually have controllers themselves (at least I haven't come across them) but they do have views, the view controls the look of the email so we have...

3)this is a the views/notifications/forgot_password.rhtml file...

As per your request a new random password has been created for your account.Your new password is <%= @password %>

You can now login and change it to something that you'll remember.

as you can see this is using the instance variable @password - that is created from the hash assigned to @body in the forgot_password method in the class/model

4) to send the email all you do is make a method call to deliver_method_name

Re: How to make a simple Contact Form

That is how far I have gotten. The form submits and I get the flash message stating it was successful, but I get no mail. I am using the same smtp setting for my current email account to test this, but so far no dice.

Re: How to make a simple Contact Form

God I love pastie! it all looks so neat and tidy!

I can't see anything immediately wrong, everything looks good from here - if the flash is being set then your begin/rescue block is obvisouly being called OK, which means the deliver_contact_message method must be returning OK - which means it must be something in the actual delivery - one thing to check, in your environment.rb (or in development.rb etc) make sure you have this line uncommented

config.action_mailer.raise_delivery_errors = true

otherwise rails won't raise errors when the mail isn't sent

other than that my advice would be to try it out with an alternate smtp server, I tend to use gmail (even though it takes a bit of extra setting up) because I've had trouble in the past with using my own server's smtp (sometimes it works, other times not)

one last thing I didn't notice in your environment.rb

ActionMailer::Base.delivery_method = :smtp

I don't know whether this is needed when using ActionMailer::Base.smtp_settings as opposed to the old ActionMailer::Base.server_settings but I tend to include it anyway!

hope one of these helps, if not I recommend trying to setup the simplest version (kinda like I outlined before) and get that working before adding on the extra layers you want for your final production app - then when it breaks you can tell where the trouble is coming in