Contact form (email)
Permalink 16 users found helpful
I made a contact form for my site by overriding the external form block (actually copy, paste, rename the existing external form files in case I need to add another form in the future to avoid conflicts with the first one).
It has 4 fields: name, email, message and captcha verification. Of course you can add as many more as you want. It sends the form to any email address you specify with all the client (javascript) and server (php) form field verification shebang. It won't send the form unless all fields are correctly filled in. It also checks the host IP, host name, proxy IP, proxy name, domain name, e.g. it won't send it unless the domain name exists. Plus it's got a repeated form submission prevention, e.g. it won't resend the form for 60 s. Plus it comes with form field injection prevention. I think it's as good and secure as it can get. The rest is up to you.
I also use the 3rdparty/Zend/Mail library as the default C5 mail helper is very basic and doesn't do what I need the form to do (for example to send both text and html email).
It's not like a package where you can build your form first, you need to know HTML, PHP, JavaScript and CSS to make it to your liking (unless you want to use it as is, just change the email address).
If anyone is interested, feel free to use/modify the attached files.
1. Unzip the archive and copy the external_form folder into your /blocks folder.
2. You can either leave the style in the /blocks/external_form/forms/contact_form.php (I've only put it in here for you) or cut and paste it into your theme's style.css file.
3. Change
$to = "YOUR_EMAIL_ADDRESS";
$subject = "YOUR_EMAIL_SUBJECT";
...
$domainrange = array("YOUR_DOMAIN_NAMES");
to suit. The $domainrange is an array of domain names you want to ban from submitting the form from, e.g.
$domainrange = array("gmail", "yahoo", "hotmail");
4. Change the form resubmission time delay if you want:
$wait_time = 60; // Wait time (s) between form re-submissions
5. You can change anything else you want in there and add more verification/validation rules.
It has 4 fields: name, email, message and captcha verification. Of course you can add as many more as you want. It sends the form to any email address you specify with all the client (javascript) and server (php) form field verification shebang. It won't send the form unless all fields are correctly filled in. It also checks the host IP, host name, proxy IP, proxy name, domain name, e.g. it won't send it unless the domain name exists. Plus it's got a repeated form submission prevention, e.g. it won't resend the form for 60 s. Plus it comes with form field injection prevention. I think it's as good and secure as it can get. The rest is up to you.
I also use the 3rdparty/Zend/Mail library as the default C5 mail helper is very basic and doesn't do what I need the form to do (for example to send both text and html email).
It's not like a package where you can build your form first, you need to know HTML, PHP, JavaScript and CSS to make it to your liking (unless you want to use it as is, just change the email address).
If anyone is interested, feel free to use/modify the attached files.
1. Unzip the archive and copy the external_form folder into your /blocks folder.
2. You can either leave the style in the /blocks/external_form/forms/contact_form.php (I've only put it in here for you) or cut and paste it into your theme's style.css file.
3. Change
$to = "YOUR_EMAIL_ADDRESS";
$subject = "YOUR_EMAIL_SUBJECT";
...
$domainrange = array("YOUR_DOMAIN_NAMES");
to suit. The $domainrange is an array of domain names you want to ban from submitting the form from, e.g.
$domainrange = array("gmail", "yahoo", "hotmail");
4. Change the form resubmission time delay if you want:
$wait_time = 60; // Wait time (s) between form re-submissions
5. You can change anything else you want in there and add more verification/validation rules.
I'm glad my email form is useful. Could anyone please make a package out of it to make it even more easier to install and modify for those who doesn't know PHP?
Hello, I got this error after sending email:
Fatal error: Uncaught exception 'Zend_Mail_Transport_Exception' with message 'Unable to send mail' in /home/content/v/o/l/vol4ikman/html/concrete/libraries/3rdparty/Zend/Mail/Transport/Sendmail.php:105 Stack trace: #0 /home/content/v/o/l/vol4ikman/html/concrete/libraries/3rdparty/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Sendmail->_sendMail() #1 /home/content/v/o/l/vol4ikman/html/concrete/libraries/3rdparty/Zend/Mail.php(973): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail)) #2 /home/content/v/o/l/vol4ikman/html/blocks/external_form/forms/controllers/contact_form.php(148): Zend_Mail->send() #3 [internal function]: ContactFormExternalFormBlockController->action_submit_form() #4 /home/content/v/o/l/vol4ikman/html/concrete/libraries/controller.php(190): call_user_func_array(Array, Array) #5 /home/content/v/o/l/vol4ikman/html/concrete/blocks/external_form/controller.php(67): Controller->runTask('action_submit_f...', Array) #6 [internal function]: ExternalFormBlockController->__call('action_submit_f...', in /home/content/v/o/l/vol4ikman/html/concrete/libraries/3rdparty/Zend/Mail/Transport/Sendmail.php on line 105
This custom template is, in my opinion, one of the best contributions yet to the Concrete5 forums.
The Form block has proven to be somewhat troublesome when trying to implement it seamlessly with a custom design. But the block rebuilds the form in <div>'s instead of tables making it infinitely customizable.
Thanks Linuxoid!
The Form block has proven to be somewhat troublesome when trying to implement it seamlessly with a custom design. But the block rebuilds the form in <div>'s instead of tables making it infinitely customizable.
Thanks Linuxoid!
Thank you. Glad I helped.
I encourage you to pay it forward. That is if you write something useful, please post it here for free for everyone to use.
I encourage you to pay it forward. That is if you write something useful, please post it here for free for everyone to use.
This is a great addition - I like being able to style the emails properly to aid usability for clients.
Is there any way the submissions could be included in the Reports area of the dashboard?
Is there any way the submissions could be included in the Reports area of the dashboard?
I think in this case you have to combine my form with the default C5 mail block.
does anyone know how to combine this with the default cf5 mail block? I would like the outputs recorded to the reports area also.
Thanks linuxoid!
Thanks linuxoid!
awesome stuff! i agree, best post ever!
Sorry to ask what may be a simple question. Once I have downloaded, customised, uploaded into the /blocks folder, how do I get this to appear on the site?
Kind regards
Dan Fyles
Kind regards
Dan Fyles
If you click on the block when the page is in edit mode (not the block, just the page) you should see a Custom Template option in that same window you normally hit edit block from. This is where you can pick from the available custom attributes for your block
Thank you for this Franz.
I am still unsure how to make the block appear on the page initially though. It is not listed in my 'Add Block' items, nor is it in the 'ready to install' section in the dashboard.
Kind regards
Dan
I am still unsure how to make the block appear on the page initially though. It is not listed in my 'Add Block' items, nor is it in the 'ready to install' section in the dashboard.
Kind regards
Dan
You go to Add Block, External Form and choose Contact Form.
Forgot to say, Thanks Linuxoid for this great block.
George
Forgot to say, Thanks Linuxoid for this great block.
George
Thanks very much. This is exactly what I did not know. I have never used external forms before.
I agree - now that I see it in action, this is a perfect and very useful addition.
Dan
I agree - now that I see it in action, this is a perfect and very useful addition.
Dan
This is great! Is there any way to specify more than one email recipient? Sorry for my ignorance of php...
In the /blocks/external_form/forms/controllers/contact_form.php, the email is sent to address(es) set by '$zm->addTo($to);', where '$to' is where you want the email to be sent to. If you want it sent to multiple addresses, simply change the variable with a single address to an array.
FYI:http://framework.zend.com/manual/en/zend.mail.adding-recipients.htm...
FYI:http://framework.zend.com/manual/en/zend.mail.adding-recipients.htm...
Sorry, you're not talking to a php programmer here... I tried the following and it didn't work.
I get the error
Fatal error: Uncaught exception 'Zend_Mail_Transport_Exception' with message 'Unable to send mail' in...
Thank you for your help.
$to = array("myemail1@mail.com", "myemail2@mail.com");
I get the error
Fatal error: Uncaught exception 'Zend_Mail_Transport_Exception' with message 'Unable to send mail' in...
Thank you for your help.
I, too, have been trying all sorts of ways to get this to send to more than one email address. I have tried this as well with no success: I am running concrete5 5.4.1. I don't get any error messages when trying this array, it just goes nowhere. Does anyone have any suggestions on how to get this to work? Thanks for any help.
$to = array("myemail1@mail.com", "myemail2@mail.com");
Well, I've got the same problem - Zend_mail doesn't like an array of addresses even though it clearly shows in their docs it does accept them. Sorry, I have no idea what to do with it. Any Zend/PHP Pros here?
Coding suggestions from someone who doesn't know code well but this verifies better:
<script type="text/javascript"> instead of just "javascript"
Don't understand this error:
character "<" is the first character of a delimiter but occurred as data
…il.test(field.value) || field.value.length < min || field.value.length > max) {
Another error: should the & be & after Main?
cannot generate system identifier for general entity "ccm_token"
…hp?cID=1&bID=58&arHandle=Main&ccm_token
Another similar error:
cannot generate system identifier for general entity "method"
…844595:1b38db62768fcc186ff85462214ba2d4&btask=passthru&method=submit_form"
Another:
haracter "&" is the first character of a delimiter but occurred as data
…n (checkField(this.name, 'Su nombre es necesario.\n(2-100 characters)', 70) &&
Thanks for helping out someone who doesn't know code well...
<script type="text/javascript"> instead of just "javascript"
Don't understand this error:
character "<" is the first character of a delimiter but occurred as data
…il.test(field.value) || field.value.length < min || field.value.length > max) {
Another error: should the & be & after Main?
cannot generate system identifier for general entity "ccm_token"
…hp?cID=1&bID=58&arHandle=Main&ccm_token
Another similar error:
cannot generate system identifier for general entity "method"
…844595:1b38db62768fcc186ff85462214ba2d4&btask=passthru&method=submit_form"
Another:
haracter "&" is the first character of a delimiter but occurred as data
…n (checkField(this.name, 'Su nombre es necesario.\n(2-100 characters)', 70) &&
Thanks for helping out someone who doesn't know code well...
Where did you get/see these errors? I don't know what they mean as I've never had such errors.
One thought though, BTW, this
is actually one line but I broken it down to a few for easy reading.
One thought though, BTW, this
<form action="<?php echo $this->action('submit_form')?>" method="post" onsubmit="return (checkField(this.name, 'Please enter your name\n(2-100 characters)', 70) && checkEmail(this.email, 'Please enter your valid email address\n(8-100 characters)', 100) && checkField(this.ccmCaptchaCode, 'Please enter image validation code\n(5 characters)', 5) && checkField(this.message, 'Please enter your message\n(2-3000 characters)', 3000));" >
is actually one line but I broken it down to a few for easy reading.
I tried putting it all on one line and still get the errors.
I am validating my html with w3 validator. check out this link:
http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fverdad...
My doctype is XHTML 1.0 Transitional. Does that matter?
Thanks!
I am validating my html with w3 validator. check out this link:
http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fverdad...
My doctype is XHTML 1.0 Transitional. Does that matter?
Thanks!
I'm not a perfectionist. The script works without problems. If the validation errors bother you, feel free to make it better.
Thanks for the great post Linuxoid!
Thanks a bunch Linuxoid this is a great form it works perfect for me!
I am trying to translate the form into my native language (Dutch), but can’t seem to find the right value’s to edit. Does anyone know the values to edit for the following buttons/tekst in the form:
Name
Email
Message
Verify
Send
Thank you for your inquiry
I am trying to translate the form into my native language (Dutch), but can’t seem to find the right value’s to edit. Does anyone know the values to edit for the following buttons/tekst in the form:
Name
Message
Verify
Send
Thank you for your inquiry
These are in the ../blocks/external_form/forms/contact_form.php Line 147 further towards the bottom in the form declaration:
and "Thank you for your inquiry" is in the ../blocks/external_form/forms/controllers/contact_form.php Line 93:
There are other error messages in the same file a few line down.
<div id="contact_form"> <form action="<?php echo $this->action('submit_form')?>" method="post" onsubmit="return (checkField(this.name, 'Please enter your name\n(2-100 characters)', 70) && checkEmail(this.email, 'Please enter your valid email address\n(8-100 characters)', 100) && checkField(this.ccmCaptchaCode, 'Please enter image validation code\n(5 characters)', 5) && checkField(this.message, 'Please enter your message\n(2-3000 characters)', 3000));" > <div> <?php //print $form->label('name', t('Name: ')); //print $form->text('name', $name, array('maxlength' => 70, 'size' => 40, 'onblur' => "check('name');")); ?> <label for="name" class="required">Name:</label> <input type="text" id="name" name="name" value="" maxlength="70" size="40" onblur="check('name');" /> </div>
Viewing 15 lines of 51 lines. View entire code block.
and "Thank you for your inquiry" is in the ../blocks/external_form/forms/controllers/contact_form.php Line 93:
$error_msg = '<div id="error_msg">If you are experiencing problems submitting the form please send an email with your query to <b>'.$to.'</b>.</div><hr />'; $no_error_msg = '<div id="noerror">Thank you for your inquiry.</div><hr />'; if (!$ip->check()) { $e->add($ip->getErrorMessage()); } if (!$captcha->check()) { $e->add(t('Incorrect image validation code. Please check the image and re-enter the code.')); $_REQUEST['ccmCaptchaCode']=''; } if (strlen($name) < 2) { $e->add(t('Name must be at least %s characters long.', 2)); } if (strlen($name) > 70) { $e->add(t('Name cannot be more than %s characters long.', 70)); }
Viewing 15 lines of 37 lines. View entire code block.
There are other error messages in the same file a few line down.
It works just great! Thanks a lot.
Great, simple but works well.
One thing; what do i need to do to make the fields remember the contents on an unsuccessful submit?
One thing; what do i need to do to make the fields remember the contents on an unsuccessful submit?
You can try storing the input data in either session variables or cookies. But I wouldn't do that as it will make auto-submission robots job easier.
Most of you are going to laugh at this question, but where am I able to change "$to = "YOUR_EMAIL_ADDRESS"?
I've opened up Dreamweaver CS5 to edit this contact form but do not see or know where I can direct it to my email address.
Any 'dummy help' is much appreciated!
Kyle
I've opened up Dreamweaver CS5 to edit this contact form but do not see or know where I can direct it to my email address.
Any 'dummy help' is much appreciated!
Kyle
Thank you linuxoid for this great post. This is really helpfull.
Ksherwood8, go to the External Form folder > Controllers > contact_form.php. From here you should be able to see and edit the line
Ksherwood8, go to the External Form folder > Controllers > contact_form.php. From here you should be able to see and edit the line
$to = "YOUR_EMAIL_ADDRESS";
I've just found this thread, good work to all! Tried implementing into a project but there seems to be a problem with the CAPTCHA image it is producing a 6 character code, but the block is only allowing 5!
Try changing the line: (inside the contact_form.php)
to: (notice that 5 changes to 6)
And change the value of the attribute maxlenght inside of the input tag to maxlenght="6"
checkField(this.ccmCaptchaCode, 'Please enter image validation code\n(5 characters)', 5) &&
to: (notice that 5 changes to 6)
checkField(this.ccmCaptchaCode, 'Please enter image validation code\n(6 characters)', 6) &&
And change the value of the attribute maxlenght inside of the input tag to maxlenght="6"
Hi,
Is this still available?
I can't seem to find a download link for the files.
Thanks
Jon
Is this still available?
I can't seem to find a download link for the files.
Thanks
Jon
Yes this is still available and it works fine ! Linuxoid attached the file in his second post(right corner, paperclip).
This is a really nice contact form. Thank you very much :-)
I've got one (maybe stupid)question about this form: I translated everything in Dutch, and that works well. But I've searched a long time in the scripts for this sentence: "Click the image to see another captcha" I can't find it. So I can't translate it....Does anyone know where I can find this sentence ?
Thanks
I've got one (maybe stupid)question about this form: I translated everything in Dutch, and that works well. But I've searched a long time in the scripts for this sentence: "Click the image to see another captcha" I can't find it. So I can't translate it....Does anyone know where I can find this sentence ?
Thanks
I just wanted to say THANK YOU so much for this contact_form!
I am a complete nub with Concrete5, I had a registration form project that I inherited and knew nothing about php or concrete5.
I was not able to get my custom external form to post to the controller file to save my life! I was able to look at your contact_form and see how you made the function call to the controller and now it works!
Your form also went a long way helping me get my captcha to finally work!
YOU ROCK my friend!!!!!
Sincerely,
James
I am a complete nub with Concrete5, I had a registration form project that I inherited and knew nothing about php or concrete5.
I was not able to get my custom external form to post to the controller file to save my life! I was able to look at your contact_form and see how you made the function call to the controller and now it works!
Your form also went a long way helping me get my captcha to finally work!
YOU ROCK my friend!!!!!
Sincerely,
James
Great work, many thx too!
Most time I need SMTP and SMTP-AUTH to sending mails via external SMTP Server. I used the following code but after "submit" the form I get a blank page. If I comment out the code, form validation works.
doesn´t work too
Need any help, please!
Thanks, mbsouth
Most time I need SMTP and SMTP-AUTH to sending mails via external SMTP Server. I used the following code but after "submit" the form I get a blank page. If I comment out the code, form validation works.
..... Loader::library('3rdparty/Zend/Mail'); $config = array('auth' => 'plain', 'username' => 'myUserName', 'password' => 'myPassWord'); $transport = new Zend_Mail_Transport_Smtp('mx.domain.tld', $config); $zm = new Zend_Mail(APP_CHARSET); Zend_Mail::setDefaultTransport($transport); $zm->setSubject($subject); $zm->setBodyText($txt_message); //$zm->setBodyHtml($html_message); $zm->addTo($to); $zm->setFrom($email); $zm->send(); .....
doesn´t work too
... //Zend_Mail::setDefaultTransport($tr); ... $zm->send($transport); ...
Need any help, please!
Thanks, mbsouth
Hi Linuxoid,
Would you send me the contact form block attachment? It doesn't seem to appear attached to your post in the current iteration of the Forums.
Would you send me the contact form block attachment? It doesn't seem to appear attached to your post in the current iteration of the Forums.
Nevermind... I now see that it is attached to the second post.
If you can make it better, please share.