Contact page

Contact page

Postby jondaley on Tue Dec 20, 2005 4:14 pm

This started out as a plugin, but ended up being easier to implement as a template. I did have to enable php code within templates, which I realize not everyone can do.

But, in case it helps someone, here goes:
contact.php (I put this in the lifetype root directory, but it could live just about anywhere)
Code: Select all
<?php

if (!defined( "PLOG_CLASS_PATH" )) {
    define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
}

include_once( PLOG_CLASS_PATH."class/net/url.class.php" );


function getVar($var){
    $vars = HttpVars::getPost();
    if($vars[$var])
        return $vars[$var];
    else{
        $vars = HttpVars::getGet();
        return $vars[$var];
    }
}


function emailValidate($address){
        // not valid
    $reg1 = "/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|[\(\)\<\>\,\;\:\"]/";
        // valid
    $reg2 = "/^.+\@(\[?).+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/";
    if (!preg_match($reg1, $address) &&
        preg_match($reg2, $address)){
        return true;
    }
    else{
        return false;
    }
}

$name = stripslashes($_POST["name"]);
$email = stripslashes($_POST["email"]);
$subject = stripslashes($_POST["subject"]);
$text = stripslashes($_POST["text"]);

$error = 0;
$mailSent = 0;

if($_POST["submit"]){
    if($name && $email && $subject && $text){
        if(emailValidate($email)){
            mail('spam@jon.limedaley.com',
                 $subject,
                 "From: " . $name . " via the web\n\n" . $text,
                 "From: $email");
            print "Mail sent.<br/>Thank you for your feedback.<br/>" .
                "You should receive an auto-reply with a ticket number shortly.<br/>";
        }
        else{
            mail('jon@limedaley.com',
                 $subject,
                 "From: ".$name." <" . $email . "> via the web\n\n".$text,
                 "From: spam@jon.limedaley.com");
            print "Mail sent.<br/>Thank you for your feedback.<br/>";
        }
        print "We will process your information and get back to " .
            "you as soon as possible.<br/><br/>\n";
        print "Back to the <a href='/'>home page</a>";
        $mailSent = 1;
        $error = 0;
    }
    else{
        print "All fields are required.  Please enter the " .
            "information and click the submit button.<br/><br/>\n";
        $error = 1;
    }
}
else{
    if($name || $email || $subject || $text){
        print "Information was not received correctly.  Please try " .
            "again, or email us at spam@jon.limedaley.com<br/><br/>\n";
        $error = 1;
    }
    else{
        print "Please submit your name, email and question<br/>\n";
    }
}

?>


then, I made a new template (I called it comments.html.template)
The "extension" or .html part doesn't really matter what you call it, but putting it as html makes it look to the user like a regular old html page.
Code: Select all
{include file="$blogtemplate/header.template" title="Comments"}
{include file="$blogtemplate/panel.template"}
  <div class="blog">

  {dynamic}
  {php}
    include("/home/limedaley/www/contact.php");

    if($mailSent == 0){
      print "<form action='/page/comments.html' method='post'>\n" .
          "Full Name:\n" .
          "<input type='text' name='name' size='20'\n" .
          "   value='".$name."' maxlength='20'><br />\n" .
          "E-mail address:\n" .
          "<input type='text' name='email' size='30'\n" .
          "    value='".$email."' maxlength='30'><br />\n" .
          "Subject/Topic:\n" .
          "<input type='text' name='subject' size='30'\n" .
          "    value='".$subject."' maxlength='30'><br />\n" .
          "Text:\n" .
          "<textarea name='text' cols='50' rows='10'>".$text."</textarea><br />\n".
          "<input type='submit' name='submit' value='Send'>\n" .
          "</form>";
    }
  {/php}
  {/dynamic}

  </div>
{include file="$blogtemplate/footer.template"}


The {dynamic} tags are needed to keep smarty from caching the php code.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

okay and the url?

Postby nik0 on Tue Dec 20, 2005 4:28 pm

Okay, i've saved first part to contact.php, I've put it to plog root dir, then I've put the contact.php.template into my current template directory.. now what will be the URL for the contact form?
nik0
 

Postby jondaley on Tue Dec 20, 2005 4:35 pm

jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Postby jondaley on Tue Dec 20, 2005 4:37 pm

My URL is http://limedaley.com/page/comments.html.
I use the so-called "interesting trick" mentioned in the wiki article.
I also have a symbolic link from /page to /static, because I think /page looks nicer than /static.
I also am only serving one blog with this installation of lifetype, so I don't need a blog identifier.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

just for the record

Postby nik0 on Tue Dec 20, 2005 4:38 pm

Okay, thanks i found it.

For others like me looking for that answer:

http://domain.of.your.site/plog-path/in ... ontact.php
nik0
 

:)

Postby nik0 on Tue Dec 20, 2005 4:39 pm

Did i said "THANKS A LOT"?Okay.. THANKS A LOT, you really saved my night ;)
nik0
 

Re: Contact page

Postby newtech1 on Tue Feb 17, 2009 4:08 pm

This is something I am looking for. Either a simple way for there to be an e-mail link on any blog that allows a visitor to send an e-mail to the blog owner without knowing the blog owner's e-mail address, or a contact form that is linked to on the blog.

I guess I could just create a contact form myself and make it a template page. But I have several templates and some users have customized templates, so it could become challenging.

There was talk about an e-mail plugin in some of the very old posts. Is there a plugin for this that I am missing?
Or a simplier way to make it so that there could be one contact.template that would be shared among all users?
Richard D'Andrea Dover
http://www.christianblogsites.com
newtech1
 
Posts: 593
Joined: Thu Oct 13, 2005 12:02 am
Location: Seattle, WA, USA

Re: Contact page

Postby jondaley on Wed Feb 18, 2009 8:15 am

You can't use my idea, since my way requires you to enable php, which you can't do unless you either don't allow template editing, or trust all of your users.

Someone did make a plugin at some point - it is on the forums somewhere. I have it on my list (from like 2 years ago) to see whether his plugin is better than my idea.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Contact page

Postby jondaley on Wed Feb 18, 2009 8:18 am

jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Contact page

Postby newtech1 on Wed Feb 18, 2009 10:57 am

How about adapting the 'Submit a Story' 'Send us a Story', plugin.
It makes entering the e-mail address as optional. What would need to be done to make the e-mail address required?

It would not be a true contact form in the sense of an e-mail being sent to the blog owner, but the blog owner could still receive info from the sender. Just would need to change the title on the page, etc.

Since I am already using the Send us a Story, I am wondering if it is straightforward for me to just rename the plugin and do some changes in locale if it will work as a different plugin. In other words would it be in conflict with the original Send us a story.

Hope I am making sense.
newtech1
 
Posts: 593
Joined: Thu Oct 13, 2005 12:02 am
Location: Seattle, WA, USA

Re: Contact page

Postby jondaley on Wed Feb 18, 2009 11:15 am

You could do that pretty easily as well. It shouldn't conflict, you just need to rename the files and classes.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Contact page

Postby newtech1 on Wed Feb 18, 2009 2:15 pm

The plugin is actually the Submissions plugin that I would use as a template.

you just need to rename the files and classes


Does this mean I would need to go to every single file and replace where it says something about submissions?

Is there a way to make the e-mail address be required?
Richard D'Andrea Dover
http://www.christianblogsites.com
newtech1
 
Posts: 593
Joined: Thu Oct 13, 2005 12:02 am
Location: Seattle, WA, USA

Re: Contact page

Postby jondaley on Wed Feb 18, 2009 2:40 pm

right. You could skip the renaming of the files, but likely to cause problems if you miss something, so renaming everything is easier.

There will (should) be a place where it validates the email address, at least to make sure it doesn't contain SQL exploits, if not validating it specifically as an email address. That place will (should) have a thing that says, "if empty, don't validate", and you just need to remove that check.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Contact page

Postby newtech1 on Fri Mar 06, 2009 8:19 pm

I am finally getting around to this.
Am I understanding things correctly that I need to go to every file in every folder and wherever there is the word $submissions I would replace it with $contactform, submissionTopic with contactformTopic, $errors.submissionTopic with $contactform,submissionTopic, etc.?
newtech1
 
Posts: 593
Joined: Thu Oct 13, 2005 12:02 am
Location: Seattle, WA, USA

Re: Contact page

Postby jondaley on Wed Mar 11, 2009 8:50 am

yes. And even places where it just says "submissions" (ie. not just $submissions). Also PluginSubmissions, etc.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Next

Return to Templates

cron