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.

Archive

Our old forums are still available as a read-only archive.

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

Contact Form - From Address Help


Go to End
Reply

15 Posts   3331 Views

Avatar
Liam

23 July 2008 at 1:13pm Community Member, 470 Posts

Hello,

I just need a simple contact form that a user can fill out, and the results are emailed to the admin. I could easily use the user defined forms cause it's good enough, except I'd really like the from address to be the user's email, not what's defined in the config file. That way when the email comes in, the admin can read the email and just click reply in their email program to respond to it.

I'd assume I have to code my own, but being a designer first, I'd love as much info on this as possible. Example code would be great.

Cheers,

Avatar
Sean

23 July 2008 at 4:54pm Forum Moderator, 921 Posts

Quickly whipped something up here:

http://pastie.org/239113

Should be somewhat self-explanatory. You'd put a template in the mysite/templates/email directory, and you can loop over the form data in there by using something like:

<% control FormData %>
Name: $Name
<% end_control %>

Avatar
Liam

24 July 2008 at 8:30am Community Member, 470 Posts

Thanks so much for the help. That's more than I expected, but fantastic. Saves me a lot of work.

I followed the steps, and the form shows up on the newly created contact page type. When I go to submit the form though, all I get is a blank screen. The form doesn't email and nothing is shown.

Am I missing something or is there an error in the code?

Avatar
Liam

29 July 2008 at 3:08pm Community Member, 470 Posts

I still haven't been able to figure out why my form won't submit.

Also, how do I define a custom template for this form? I tried using the function forTemplate() in the class, but even after a /flush=1 I still get the standard form. I included the new template in the /templates/includes directory.

Avatar
Sean

30 July 2008 at 5:34pm Forum Moderator, 921 Posts

Submit problem:

Try putting die('here') at the end of the doForm() function. Try submit again and see if it spits out "here" in the browser.

Template:

You need to create a new class for your form if you want to define a custom template. This means doing something like this:

http://pastie.org/243869

Then, in the ContactPage_Controller class, remove the doForm() function as per my previous example, and replace the Form() function with this one:

function Form() {
   return new MyForm($this, 'Form');
}

Avatar
Liam

31 July 2008 at 7:22am Community Member, 470 Posts

Okay I got the new template up and running perfectly with the new code you showed.

The form still doesn't submit though. I tried putting in the die() function at the end of the doform function, but it didn't show up. I then tried putting it at the start of the doform() function, and still nothing.

Here is the code I have in my ContactPage.php http://pastie.org/244292

It seems like a small error somewhere, but nothing stands out to me.

Avatar
Sean

31 July 2008 at 9:26am (Last edited: 31 July 2008 9:27am), Forum Moderator, 921 Posts

Hmm, that's odd.

Here's what I did:

1. I took your code from here: http://pastie.org/243869

2. Pasted it into ContactPage.php inside mysite/code, ran db/build?flush=1

3. Applied ContactPage to any page in the CMS, and viewed the page to show the form.

4. Tried submitting the form, and it worked fine for me - I put a die('here') at the top of doForm() and it showed that text in the browser after submitting.

Is this what you're doing as well?

Here's the code that works for me, copied and pasted back for sanity reasons: http://pastie.org/244406

Cheers,
Sean

Avatar
Liam

31 July 2008 at 11:59am Community Member, 470 Posts

That's pretty much what I've done. I've run /db/build?flush=1 after installing the code and assigning the page type to the contact page.

The form shows up no problem, it's just the submitting it where it chokes. The URL after is /contacts/?executeForm=Form and is just a white page.

The only thing I can think of is that I'm running 2.2.2 stable, not trunk. Not sure if that has anything to do with it.

Emails are sending as I setup a custom newsletter after learning forms from this example. Users were subscribed perfectly and some sample newsletter were sent and received.

Go to Top