LemonStand Forum: Contact Us Page - LemonStand Forum

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Contact Us Page

#1 User is offline   temma2k2 

  • Website Developer
  • PipPipPip
  • Group: Members
  • Posts: 126
  • Joined: 14-January 10
  • LocationDarlington, United Kingdom

Posted 06 March 2010 - 01:53 PM

Hi All,

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
0

#2 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,631
  • Joined: 31-October 09

Posted 07 March 2010 - 07:12 PM

Hi, Sam!

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 User is offline   temma2k2 

  • Website Developer
  • PipPipPip
  • Group: Members
  • Posts: 126
  • Joined: 14-January 10
  • LocationDarlington, United Kingdom

Posted 08 March 2010 - 12:41 PM

Hi Aleksey,

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
0

#4 User is offline   mote 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 69
  • Joined: 17-February 10

Posted 12 May 2010 - 10:41 PM

Hey Aleksy

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 ...
0

#5 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,631
  • Joined: 31-October 09

Posted 13 May 2010 - 01:24 AM

Hi, guys!

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

#6 User is offline   mote 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 69
  • Joined: 17-February 10

Posted 13 May 2010 - 03:56 AM

Perfect Aleksy and thank you.
0

#7 User is offline   Wayde Christie 

  • Member
  • Group: Members
  • Posts: 12
  • Joined: 03-July 10
  • LocationNewcastle, Australia

Posted 04 July 2010 - 07:35 PM

+1 for the Contacts Module!

:)
0

#8 User is offline   pmeissner 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 128
  • Joined: 11-January 10
  • LocationElverson, PA

Posted 13 July 2010 - 02:28 AM

read the "little moose" case study and found this. perfect. +1 for the Contact Module :D

This post has been edited by pmeissner: 13 July 2010 - 02:29 AM

0

#9 User is offline   Jim 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 56
  • Joined: 12-April 10

Posted 13 July 2010 - 06:16 AM

Yup, it works a treat.
0

#10 User is offline   Jim 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 56
  • Joined: 12-April 10

Posted 22 August 2010 - 08:47 AM

Any news on the contact module yet folks? We've just started getting spam through from ours and I'd rather wait than tinker about trying to enable Captcha myself!

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

0

#11 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,631
  • Joined: 31-October 09

Posted 22 August 2010 - 01:17 PM

Hi, Jim!

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 User is offline   Jim 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 56
  • Joined: 12-April 10

Posted 22 August 2010 - 01:43 PM

So if I wanted to create a field which needed to have the answer 'blue' what would I change in the simplecontactform_actions.php file
0

#13 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,631
  • Joined: 31-October 09

Posted 22 August 2010 - 02:09 PM

Jim, you need to find a suitable captcha or other anti-spam tool and follow the implementation instructions. The contact form module does not contain any captcha support, but you can extend it as you would do with any other contact or comment form. The on_postMessage() function is a place where you need to add conditions which will check whether the visitor chose a correct answer.

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 User is offline   Jim 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 56
  • Joined: 12-April 10

Posted 22 August 2010 - 03:36 PM

I've placed a hidden field into the form, if it has anything entered I want it to be rejected as spam.

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;
}

0

#15 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,631
  • Joined: 31-October 09

Posted 22 August 2010 - 03:43 PM

Jim, did you miss the != in your code example?

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 User is offline   Stephanie_42 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 37
  • Joined: 31-December 10

Posted 25 February 2011 - 10:38 AM

View PostAleksey, on 13 May 2010 - 01:24 AM, said:

Hi, guys!

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
0

#17 User is offline   Eric 

  • Developer
  • PipPipPip
  • Group: Members
  • Posts: 1,290
  • Joined: 04-August 10
  • LocationVancouver, Canada

Posted 25 February 2011 - 12:27 PM

Hi Steph,

Yes it can.

Sorry again, for the broken downloads. I've re-attached it.

Attached File(s)


0

#18 User is offline   Stephanie_42 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 37
  • Joined: 31-December 10

Posted 26 February 2011 - 07:59 PM

Thanks a million, it works like a dream! +1 for a contact module ;)


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.
0

#19 User is offline   Beats 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: 18-January 11

Posted 01 March 2011 - 10:56 PM

How can I make the simplecontactmodule work in a partial instead of on it's own page?

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!
0

#20 User is offline   Eric 

  • Developer
  • PipPipPip
  • Group: Members
  • Posts: 1,290
  • Joined: 04-August 10
  • LocationVancouver, Canada

Posted 02 March 2011 - 10:56 AM

There is another Contact module, by the way. It differs slightly, it uses an Ajax action instead of a Page action, and an Email Template instead of a flatfile partial. It's used in the Utility theme (and can also be found here).

View PostBeats, on 01 March 2011 - 10:56 PM, said:

How can I make the simplecontactmodule work in a partial instead of on it's own page?

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
0

Share this topic:


  • 2 Pages +
  • 1
  • 2

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users