We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Auto Populate A Custom Field

Development and Programming

FrankJohnson's avatar
FrankJohnson
150 posts
16 years ago
FrankJohnson's avatar FrankJohnson

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

       
FrankJohnson's avatar
FrankJohnson
150 posts
16 years ago
FrankJohnson's avatar FrankJohnson

Any ideas on this?

Thanks, Frank

       
wornjacket's avatar
wornjacket
98 posts
15 years ago
wornjacket's avatar wornjacket

Looks like a syntax error.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.