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


8 Posts   1445 Views


11 December 2012 at 8:11am Community Member, 470 Posts

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 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'.


11 December 2012 at 1:59pm 4085 Posts

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("") 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", "", "Testing this")
      return $form->render();

Silverstripe tips, tutorials, screencasts, and more.


12 December 2012 at 6:05am Community Member, 470 Posts

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'


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.


13 December 2012 at 2:47am (Last edited: 13 December 2012 2:48am), 4085 Posts

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 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, 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.

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.


13 December 2012 at 5:15am Community Member, 470 Posts

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.

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


13 December 2012 at 5:21am 4085 Posts

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 and the form is on, 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 <>");

Silverstripe tips, tutorials, screencasts, and more.


13 December 2012 at 7:51am Community Member, 470 Posts

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.



13 December 2012 at 8:58am 4085 Posts

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.