I need to post-process entries to a weblog when they are created or modified. Specifically I want to auto-fill certain fields if the user has left them empty, so that they end up non-empty in the database. note that i am using the EE publish/edit form and not a saef.
It seems I need to write an extension that uses the submit_new_entry_end hook? but it’s unclear from the docs whether this hook is just to notify when an entry is created or modified… I need to be able to change the data before it’s sent to the database…
please advise on the best way to approach this, and if there’s an extension already written that would be a good starting point for this task please let me know. thanks!
I’m going to shift to ‘Extensions’- because you’re right, that’s the way to go on this one. I suspect there are a number of existing extensions you could riff off of. I’ve got one open- uses the SAEF, but I suspect it’s just a matter of changing the hook. The gist is:
<?php
/*
=========================================================
This Extension is intended for use with ExpressionEngine.
ExpressionEngine is Copyright (c) 2003 pMachine, Inc.
http://www.pmachine.com/
=========================================================
by da cow
========================================================
*/
if ( ! defined('EXT'))
{
exit('Invalid file request');
}
class Saef_modify
{
var $settings = array();
var $name = 'SAEF Modify';
var $version = '1.0';
var $description = 'SAEF - modify post data for the cracktastic forms';
var $settings_exist = 'n';
var $docs_url = '';
var $url_fields = array(11, 15, 61, 62, 63);
function mod_post()
{
global $FNS, $IN, $EXT, $OUT, $STAT;
if ($EXT->last_call !== FALSE)
{
$s = $EXT->last_call;
}
$this->variable_check();
}
function variable_check()
{
global $FNS, $IN, $EXT, $OUT;
foreach ($this->url_fields AS $val)
{
if (isset($_POST['field_id_'.$val]) AND $_POST['field_id_'.$val] != '' AND substr($_POST['field_id_'.$val], 0, 4) != "http" AND ! ereg('://', $_POST['field_id_'.$val]))
{
$_POST['field_id_'.$val] = "http://".$_POST['field_id_'.$val];
}
}
}
function activate_extension()
{
global $DB;
$DB->query($DB->insert_string('exp_extensions',
array(
'extension_id' => '',
'class' => "Saef_modify",
'method' => "mod_post",
'hook' => "weblog_standalone_insert_entry",
'settings' => "",
'priority' => 1,
'version' => $this->version,
'enabled' => "y"
)
)
);
}
function disable_extension()
{
global $DB;
$DB->query("DELETE FROM exp_extensions WHERE class = 'Saef_modify'");
}
}
?>
I’d use the submit_new_entry_start, instead of the saef hook I was using. And the above is simplified- sorta. No reason for variable_check() to exist- just pull it all into the mod_post function and return. I did a lot of ripping out to simplify things.
That help?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.