17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 3051 Views |
-
Contact Form - From Address Help

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,
-
Re: Contact Form - From Address Help

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 %> -
Re: Contact Form - From Address Help

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?
-
Re: Contact Form - From Address Help

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.
-
Re: Contact Form - From Address Help

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');
} -
Re: Contact Form - From Address Help

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.
-
Re: Contact Form - From Address Help

31 July 2008 at 9:26am Last edited: 31 July 2008 9:27am
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 -
Re: Contact Form - From Address Help

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.
| 3051 Views | ||
| Go to Top | Next > |


