Contact Us Page
#1
Posted 06 March 2010 - 01:53 PM
Just wondering how i would go about implementing a Contact Us page with a form that uses an admins details to send the email to?
Cheers
Sam
#2
Posted 07 March 2010 - 07:12 PM
We are going to issue the Contacts module after the V1 release. We use this module on LemonStand website. It supports contact forms and email subscriptions. But until we publish the module, you will need to write custom code in order to send emails from LemonStand pages, and you should know PHP. I can give you some tips, of course.
First, you need to create a page with a contact form. Also, you need to decide whether you want use AJAX or regular POST for sending the form request to the server. You can use both methods (implement the graceful degradation approach by assigning a JavaScript handler on the form onsubmit event), but in this case you will need to repeat the email sending code in two places. If you will use AJAX, you will need to write an AJAX handler on the AJAX tab of the Edit Page form. You can find details about implementing AJAX handlers on this page: http://lemonstandapp.com/wiki/ajax/
If you will handle regular POST requests, you will need to write some code in the Post Action Code field of the Action tab (Edit Page form). In this code you should check whether a visitor clicked the Send button. You can do it in the following way:
if (post('send_button_name'))
{
// message sending code
}LemonStand uses the PHP Mailer class and you need to include the class script first. After that you will need to create and configure the mailer object. Fortunately, LemonStand has a special class, which can apply email configuration to PHP Mailer objects. Code example:
require_once PATH_APP."/modules/core/thirdpart/class.phpmailer.php"; $Mail = new PHPMailer(); $Mail->Encoding = "8bit"; $Mail->CharSet = "utf-8"; $Mail->From = $settings->sender_email; // You can specify alternative FROM email address here $Mail->FromName = $settings->sender_name; // You can specify alternative sender name here $Mail->Sender = $settings->sender_email; // You can specify alternative sender email address here $Mail->Subject = 'Some subject'; $Mail->WordWrap = 0; $settings = System_EmailParams::get(); $settings->configure_mailer($Mail); $Mail->Body = 'Some text in HTML format'; $Mail->AltBody = 'Some text in plain text format, if needed'; $Mail->Send();
It could be a little tricky, but once the Contacts module become public, it will be much simpler to send email messages from LemonStand.
Let me know if you need more help!
#3
Posted 08 March 2010 - 12:41 PM
Cheers for getting back to me on this. That module cant come soon enough for me as my clients all use contact forms, but no worries i can write my own in the mean time.
Thanks for giving me the starting point on where to start pulling information from for email settings
Cheers
Sam
#4
Posted 12 May 2010 - 10:41 PM
I just need to build a very simple email form, I have seen this discussion and am keen to see the module as well.
In the meantime I am trying to replicate the PHP I have used on other sites.
Here is the form on my page:
<form method="post" action="/resources/contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name"/>
<label for="Phone">Phone:</label>
<input type="text" name="Phone" id="Phone" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
On other sites I just have the following PHP as the /resources/contactengine.php however this does not seem to have been processed by Lemonstand.
I don't have a vast knowledge of PHP, so perhaps I am missing the obvious! Perhaps I should just be putting this code in the Post action part of the contact.php page?
Here is the code
<?php
$EmailFrom = "orders@domain.com";
$EmailTo = "orders@domain.com";
$Subject = "Website Form";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Perhaps I am miles off on this ...
#5
Posted 13 May 2010 - 01:24 AM
I just developed a very simple module for sending email from LemonStand stores. You can use it until we publish an official contact module (and after this point, of course, if you wish). This module will not be included to the LemonStand repositories. Download it from here, extract to the modules directory and customize as you need. We will never be updating it, so your changes will not be overridden.
After you extract the module, you will need to create a contact us page (or maybe you already have one). Please select the simplecontactform:contact_page action for the contact page (please find the screenshot attached). Below is a template code for the contact form:
<?= flash_message() ?>
<? if ($message_sent): ?>
<p>Your message has been sent. Thank you!</p>
<? else: ?>
<?= open_form() ?>
<label for="name">Your name</label>
<input id="name" name="name" type="text" value="<?= h(post('name')) ?>"/>
<label for="phone">Phone number</label>
<input id="phone" name="phone" type="text" value="<?= h(post('phone')) ?>"/>
<label for="email">Email</label>
<input id="email" name="email" type="text" value="<?= h(post('email')) ?>"/>
<label for="message">Message text</label>
<textarea id="message" name="message"><?= h(post('message')) ?></textarea>
<input type="submit" value="Send" name="post_message"/>
</form>
<? endif ?>
You can customize it, but keep the input element names unchanged (including the submit element name).
Also you need to configure recipients for the website messages. Go to the config/config.php file and add the following lines to the bottom:
/*
* Contact form configuration
*/
$CONFIG['contact_email_recipients'] = array('email1@gmail.com', 'email2@gmail.com');
$CONFIG['contact_email_subject'] = 'New message';The contact_email_recipients parameter can contain any number of recipients. The second parameter allows to customize the message subject.
By default the name, email and message fields a required. You can change this behavior in the /modules/simplecontactform/classes/simplecontactform_message.php script.
Aleksey
#8
Posted 13 July 2010 - 02:28 AM
This post has been edited by pmeissner: 13 July 2010 - 02:29 AM
#10
Posted 22 August 2010 - 08:47 AM
Alternatively, can I edit the temporary form you guys provided with a 2+2= 'what' question?
This post has been edited by Jim: 22 August 2010 - 09:09 AM
#11
Posted 22 August 2010 - 01:17 PM
No news yet, sorry.
You can implement the captcha or any other protective mechanism by modifying the contact form code. This module is never overridden when you update LemonStand, so it is safe to modify it.
You can look into the classes/simplecontactform_actions.php file. The on_postMessage() function is called when a visitor clicks the Submit button on the form. You can add captcha processing code to the beginning of the function.
Thank you
#12
Posted 22 August 2010 - 01:43 PM
#13
Posted 22 August 2010 - 02:09 PM
You can trigger an error in case if the answer is not correct by throwing the exception:
public function on_postMessage()
{
if ( ... some captcha checking condition ... )
throw new Phpr_ApplicationException("You entered incorrect value");
SimpleContactForm_Message::send();
$this->data['message_sent'] = true;
}Thank you
#14
Posted 22 August 2010 - 03:36 PM
Something like the following should work, but isn't?
public function on_postMessage()
{
if ($_POST['hiddenfieldname'] "")
throw new Phpr_ApplicationException("Oh dear, you look like a spammer");
SimpleContactForm_Message::send();
$this->data['message_sent'] = true;
}
#15
Posted 22 August 2010 - 03:43 PM
I believe the following should work:
public function on_postMessage()
{
if (post('hiddenfieldname') != "")
throw new Phpr_ApplicationException("Oh dear, you look like a spammer");
SimpleContactForm_Message::send();
$this->data['message_sent'] = true;
}You can use the traceLog() function to debug your code. It sends any data you pass to the function to the logs/info.txt file:
public function on_postMessage()
{
traceLog($_POST); // this will send the POST data to the logs/info.txt
if (post('hiddenfieldname') != "")
throw new Phpr_ApplicationException("Oh dear, you look like a spammer");
SimpleContactForm_Message::send();
$this->data['message_sent'] = true;
}Thank you
#16
Posted 25 February 2011 - 10:38 AM
Aleksey, on 13 May 2010 - 01:24 AM, said:
I just developed a very simple module for sending email from LemonStand stores. You can use it until we publish an official contact module (and after this point, of course, if you wish). This module will not be included to the LemonStand repositories. Download it from here, extract to the modules directory and customize as you need. We will never be updating it, so your changes will not be overridden.
After you extract the module, you will need to create a contact us page (or maybe you already have one). Please select the simplecontactform:contact_page action for the contact page (please find the screenshot attached). Below is a template code for the contact form:
<?= flash_message() ?>
<? if ($message_sent): ?>
<p>Your message has been sent. Thank you!</p>
<? else: ?>
<?= open_form() ?>
<label for="name">Your name</label>
<input id="name" name="name" type="text" value="<?= h(post('name')) ?>"/>
<label for="phone">Phone number</label>
<input id="phone" name="phone" type="text" value="<?= h(post('phone')) ?>"/>
<label for="email">Email</label>
<input id="email" name="email" type="text" value="<?= h(post('email')) ?>"/>
<label for="message">Message text</label>
<textarea id="message" name="message"><?= h(post('message')) ?></textarea>
<input type="submit" value="Send" name="post_message"/>
</form>
<? endif ?>
You can customize it, but keep the input element names unchanged (including the submit element name).
Also you need to configure recipients for the website messages. Go to the config/config.php file and add the following lines to the bottom:
/*
* Contact form configuration
*/
$CONFIG['contact_email_recipients'] = array('email1@gmail.com', 'email2@gmail.com');
$CONFIG['contact_email_subject'] = 'New message';The contact_email_recipients parameter can contain any number of recipients. The second parameter allows to customize the message subject.
By default the name, email and message fields a required. You can change this behavior in the /modules/simplecontactform/classes/simplecontactform_message.php script.
Aleksey
Hey, can this still be used for the most current version of lemonstand?
also, i don't see any screen shot and where Aleksey says "download it here" doesn't link to anything?
any pointers would be great, since i''d love to use a form that's more "lemonstand-y" than not
thanks!
Steph
#17
Posted 25 February 2011 - 12:27 PM
Yes it can.
Sorry again, for the broken downloads. I've re-attached it.
Attached File(s)
-
simplecontactform.zip (5.13K)
Number of downloads: 81
#18
Posted 26 February 2011 - 07:59 PM
Quick question about this module/form - is it possible to have multiple instances of this form on one site?
they would go to the same receiving email, but need different subject lines/fields.
if I have to roll my own code for a second form that's cool, I'm just curious.
#19
Posted 01 March 2011 - 10:56 PM
The form will be part of the Product Page, so I'm not able to set the simplecontact action. Is there a way where I can make it work for the partial?
Thanks!
#20
Posted 02 March 2011 - 10:56 AM
Beats, on 01 March 2011 - 10:56 PM, said:
The form will be part of the Product Page, so I'm not able to set the simplecontact action. Is there a way where I can make it work for the partial?
There's a few things you could do. I haven't tested these so it may not be 100% accurate, just to give you an idea.
1) The simplest would probably be to change the form src path, pointing it to a different page that uses the simplecontact action.
<?= open_form(array('src' => '/my-page-here')) ?>2) You could use an Ajax handler, then manually call the simplecontact action.
function my_ajax_handler($controller) {
Cms_ActionManager::execAction('simplecontactform:contact_page', $controller);
}3) I think you can also do the above in your Pre Action code.
Cms_ActionManager::execAction('simplecontactform:contact_page', $controller);Thank you

Help

















