Hi. I’m trying to develop an extension for my clients’ use that would auto populate a hidden, custom field with the contents of other fields (title and url_title) when a client uses a stand alone edit form.
What I need seems very similar to Robin’s saef_title extension so I thought I would take a stab at revising it for my own needs (even though I’ve never tried to develop and extension and don’t even write php, although when I look at a script’s code, I can usually understand what is happening).
What I want to do is auto populate the hidden custom field with something like this:
New blog post: (the entry’s title) (the entry’s url)
and then use Solspace’s new Entry Notifications extension to send an email to ping.fm whenever the client posts to their blog.
Here is my first stab at revising Robin’s code:
<?php
if ( ! defined('EXT'))
{
exit('Invalid file request');
}
class Saef_autopopcustom
{
var $settings = array();
var $name = 'SAEF Auto Populate Custom Field';
var $version = '1.0.0';
var $description = 'Autopopulates a custom field from two other custom fields';
var $settings_exist = 'n';
var $docs_url = 'http://www.franknjohnson.com/';
// -------------------------------
// Constructor - Extensions use this for settings
// -------------------------------
function Saef_autopopcustom($settings='')
{
$this->settings = $settings;
}
// END
function make_customfield()
{
$_POST['ping'] = 'New blog post:' $_POST['ping']'
http://www.franknjohnson.com/index.php/site/comments/'.$_POST['url_title']'/';
return;
}
// END
// --------------------------------
// Activate Extension
// --------------------------------
function activate_extension()
{
global $DB, $PREFS;
$DB->query($DB->insert_string('exp_extensions',
array('extension_id' => '',
'class' => "Saef_autopopcustom",
'method' => "make_customfield",
'hook' => "weblog_standalone_insert_entry",
'settings' => "",
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
}
// END
// --------------------------------
// Update Extension
// --------------------------------
function update_extension($current='')
{
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
if ($current > '1.0.0')
{
// Update to next version 1.0.1
}
$DB->query("UPDATE exp_extensions
SET version = '".$DB->escape_str($this->version)."'
WHERE class = 'Saef_autopopcustom'");
}
// END
function settings()
{
$settings = array();
return $settings;
}
// END
function disable_extension()
{
global $DB;
$sql = "DELETE FROM exp_extensions WHERE class = 'Saef_autopopcustom'";
$DB->query($sql);
}
}
// END Class
?>
When I upload this extension and then go to Extensions Manager, I get this error (before even getting to the page):
Parse error: syntax error, unexpected T_VARIABLE in (path to extensions folder)/ext.saef_autopopcustom.php on line 30
Line 30 has this code (I split that line into two lines above so that it would all display):
$_POST['ping'] = 'New blog post:' $_POST['ping']'
The revision I made on that line was to change “title” to “ping” (the short name of my custom field).
Obviously, I’m not allowed to do that, but since I have no experience with developing extensions or php, I’m at a loss as to how to proceed to fix it (if, of course, what I want to do is possible at all).
Can anyone offer any help?
Thanks! Frank
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.