10682 Posts in 2793 Topics by 1518 members
Jump to:If this is your first visit, you will need to register before you can post. However, you can browse all messages below.
| Page: 1 , 2 | go to end | Reply | |
| Author | Topic: Contact Form - From Address Help | 1586 views |

23 July 2008 at 1:13pm
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,

23 July 2008 at 4:54pm
Quickly whipped something up here:
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 %>

24 July 2008 at 8:30am
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?

29 July 2008 at 3:08pm
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.

30 July 2008 at 5:34pm
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:
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');
}

31 July 2008 at 7:22am
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.

31 July 2008 at 9:26am
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
Last edited: 31 July 2008 at 9:27am

31 July 2008 at 11:59am
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.
| 1586 views | |||
| go to top | Reply Next > |