Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Uncle Cheese's Contact Form Module


Reply


8 Posts   1453 Views

Avatar
Liam

Community Member, 470 Posts

11 December 2012 at 8:11am

https://github.com/bluehousegroup/silverstripe-contact-form

Not sure if anybody else uses this and can help or if this will be for him.

I have 2 minor things I want to do.

1. Is there a way to return the form with a different ID other than #Form_Form so I can style it easier with CSS?

public function Form() {
       return ContactForm::create('Form', $this->To, $this->Subject)
// stuff here

If I change to " return ContactForm::create('ContactForm', $this->To, $this->Subject) " and setup the allowed_actions the form never submits. It goes to the page domain.com/contactpage/ContactForm but no email.

2. Upon form completion I want the page to reload back to the success message/form area. If the page is long and the form is beneath the fold, users might be confused whether the form submitted, or miss errors, or not scroll back down to see.

I've tried setting ->setSuccessURL() but I get the error the method 'getsuccessurl' does not exist on 'Form'.

Avatar
UncleCheese

4085 Posts

11 December 2012 at 1:59pm

Hey, Liam,

Sorry I dropped out. I have some answers for you.

1) Use ->getForm()->setHTMLID("YourID");

2) I fixed the bug that was causing the getSuccessURL() error.

3) If you're not getting emails, make sure you use Email::setAdminEmail("you@example.com") in your _config.php. Otherwise it comes from God-knows-what and will likely not even reach your spam folder.

Here's the code I used in my test:

   public function ContactForm() {
      $form = ContactForm::create("ContactForm", "aaroncarlino@gmail.com", "Testing this")
         ->addField(TextField::create("Foo"))
         ->setSuccessURL($this->Link('success'));
      $form->getForm()->setHTMLID("Foo");
      return $form->render();
   }

---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

Avatar
Liam

Community Member, 470 Posts

12 December 2012 at 6:05am

Perfect. That fixes everything now. The email was only not sending when I was using the setSuccessURL() before but now that's fixed.

Not that this matters because I'm using setHTMLID() now to set the form id, but if I try to set the name to anything other than "Form" I get the error

the method 'fortemplate' does not exist on 'ContactForm'

code:

public function ContactForm() {
       $form = ContactForm::create('ContactForm', $this->To, $this->Subject)

But if I set everything to Form it works. Just curious but not a big deal.

1. I think I mentioned this before but I don't believe ->setSuccessMessage($this->SuccessMessage) returns HTML text.

2. I know there are reasons not to because of SPF records etc, but is there anyway to set the from email address to the email field the user fills out in the form? This isn't a big deal because I know you can reply to the email and it goes to the address, but it just looks odd for clients to see and I have to explain.

Avatar
UncleCheese

4085 Posts

13 December 2012 at 2:47am

Edited: 13/12/2012 2:48am

Hi, Liam,

Glad it's working better. For the HTMLID piece, did you see the code I pasted? It's a little odd. You have to get the Form object off the ContactForm object, update the HTMLID, and then run ->render() on the ContactForm object. Based on the error you're getting, it looks like you've forgotten to run ->render().

The idea of the ContactForm object not being a Form is kind of lame. It was done essentially to make the module adaptable to BootstrapForms, so that the ContactForm was this conceptual layer that could dynamically become either a Form or a BootstrapForm at runtime. I realized later that this wasn't necessary since in BootstrapForms I provided a method that transforms a Form into a BootstrapForm. So all of that will be redone, and ContactForm will just be a form, and the whole ->render() thing will go away.

1) The success message doesn't return HTMLText because the success message in the Form.ss template is in a paragraph tag, meaning if you create a success message in TinyMCE, you'll get nested p tags when the form rendered, because TinyMCE always wraps everything in at least a paragraph tag. The success message is in a div in BootstrapForm.ss, so I guess we could conditionally remove the strip_tags() function when BootstrapForms is enabled. Kind of ugly, though. If you want to play around with it, it's line 55 of ContactFormControls.

2) There is a provision for this in the module.
->setReplyToField("MyEmailField")

By default, it's "Email," so if you have a field called "Email," you dont' need to run that method.

---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

Avatar
Liam

Community Member, 470 Posts

13 December 2012 at 5:15am

I'm only getting an error when I change the function name to anything other than Form. I was using the render() part but I was only curious because I saw your code and it seems to work. I actually copy and pasted your code in this thread to test and it still didn't work. Weird.

It's not worth spending time on because it does work fine with the name is Form.

1) Makes sense about the html message. I was just confused because in admin you have set up the success message as tinymce field so I was expecting html.

2) The reply to mail does work, but the name field in my mail client shows up blank or the admin email address set in my config if I have one. That is what can be confusing for clients.

What I'm talking about is having that email show up as the _Name_ (from address) in the mail client or a field that user has filled out for their name instead of email address.

Here is a screenshot of Sparrow when no admin is set in config. It's blank.

http://liamwhittle.ca/uploads/contactmodule_b705.jpg

That's why I mentioned I'm aware of issues with SPF records and such that could cause problems.

Avatar
UncleCheese

4085 Posts

13 December 2012 at 5:21am

Well, "from" and "reply-to" are very different things. You can set the reply-to of the email for the convenience of replying to the person who submitted the contact form, but you can't set the "from" address to that same email. The reason being if I set the from address to me@example.com and the form is on silverstripe.com, that raises a major red flag with your email provider. They're going to look at the mismatch of the originating IP and compare it to the from address and classify it as spam. So the best practice is to use a persistent From address that is in alignment with the site's primary domain name.

If you want to have more control over the From address, I think it falls back on the default admin email, so you can set that to use a from name.

Email::setAdminEmail("Uncle Cheese <unclecheese@example.com>");

---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

Avatar
Liam

Community Member, 470 Posts

13 December 2012 at 7:51am

Ya I am aware of the issues but was wondering anyway.

Thanks for clearing that up and good to hear you're planning on continuing work with this module. Wasn't sure if it was a forgotten one.

Thanks!

Avatar
UncleCheese

4085 Posts

13 December 2012 at 8:58am

No problem. It's a brand new one, so it's far from forgotten. Glad someone's getting use out of it. I use it on almost all of my sites.

---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com