Search

In another thread I suggested that we add a “how-to” category to this forum. The following is the kind of content that could be placed under that category:

I wanted a new feature for my blog site that fills the Author, Email and Website fields of my comment form with data collected from a previous comment. That is, if a visitor has made a comment before, the visitor won’t have to fill in those fields on the next comment (provided that the visitor is using the same computer). I accomplished this by placing a cookie on the visitor’s computer which holds the visitor’s name, email address and website URL, and then retrieving that information before a comment form is displayed.

The cookie is created in my save-comment event. The last six lines in its __trigger() function now look like this:

include(TOOLKIT . '/events/event.section.php');
$cookie_value = $_POST['fields']['author'].'~'
                .$_POST['fields']['email'].'~'
                .$_POST['fields']['website'];
setcookie('VISITORDATA', $cookie_value, time()+2592000, '/symphony-2');
return $result;

The cookie is reset on each new comment. The expiration time is set for 30 days after the latest comment. If the time between comments by the same visitor is always less than 30 days the cookie will always exist and the comment form will always be pre-filled (that is, all except the comment box itself).

The next step is getting the visitor information into the comment form. This very simple custom data source performs that function:

<?php
    require_once(TOOLKIT . '/class.datasource.php');
    Class datasourcevisitordata extends Datasource{
        function about(){
            return array('name' => 'VisitorData');   
        }
        function __construct(&$parent, $env=NULL, $process_params=true){
            parent::__construct($parent, $env, $process_params);
            $this->_dependencies = array();
        }
        function grab(&$param_pool){
            $visitordata = explode('~', $_COOKIE['VISITORDATA']);
            $param_pool['cmt_author'] = $visitordata[0];
            $param_pool['cmt_email'] = $visitordata[1];
            $param_pool['cmt_website'] = $visitordata[2];
        }
    }
?>  

All pages that have a comment form were set to include this data source. That makes the three parameters available to those pages’ XSL templates.

Then the comment form template was modified to use these parameters to set the field values:

<input type="text" name="fields[author]" value="{$cmt_author}" />
<input type="text" name="fields[email]" value="{$cmt_email}" />
<input type="text" name="fields[website]" value="{$cmt_website}" />

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details