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

Problem creating an textarea settings field for an extension

Development and Programming

Russ Back's avatar
Russ Back
142 posts
about 15 years ago
Russ Back's avatar Russ Back

Hi all

I’m trying to add an extension setting textarea field but all I can get it to do is display it as a text input. Here’s the code:

$this->settings = array(
            'api_email'                    => '',
            'api_password'                => '',
            'email_for_notification'    => $this->EE->config->item('webmaster_email'),
            'trigger_field'                => '',
            'trigger_value'                => 'y',
            'sms_number_field'            => '',
            'html_email_content'        => array('t', 't', ''),
            'text_email_content'        => array('t', 't', '')
        )

The two fields at the bottom are the ones I’m struggling with - they should be textarea fields that accept a string and default to an empty string. When viewing the extension settings, I see a text input instead of a textarea with the default value of ‘Array’.

Where have I gone wrong there?

Also I am finding I need to click on the Enable link twice in the Add-ons > Extensions screen before the extension shows as being enabled. Any ideas what that might be?

Thanks

[Mod Edit: Moved to the Development and Programming forum]

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
about 15 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

Russ,

I copy and pasted your code into an extension locally and I see textareas as expected. Can you show your entire settings() method here?

As for the installation issue - can you show us the activate_extension() method code as well?

       
Russ Back's avatar
Russ Back
142 posts
about 15 years ago
Russ Back's avatar Russ Back

Hi Erik

Here’s the settings method:

function settings()
    {
        $settings = array();
    
        $settings['api_email']                = '';
        $settings['api_password']            = '';
        $settings['email_for_notification']    = $this->EE->config->item('webmaster_email');
        $settings['trigger_value']            = 'y';
        $settings['html_email_content']        = '';
        $settings['text_email_content']        = '';
        
        $freeform_fields = $this->_get_freeform_fields();
        $member_fields = $this->_get_member_fields();
        
        if (sizeof($freeform_fields) > 0)
        {
            $settings['trigger_field']    = array('s', $freeform_fields);
        }
        
        if (sizeof($member_fields) > 0)
        {
            $settings['sms_number_field']    = array('s', $member_fields);
        }
                
        return $settings;
    }

The _get_freeform_fields() and _get_member_fields() are private methods that return an array of field labels and names so that the user can select a relevant field from the database.

And my activate method:

<pre><code>function activate_extension() { $this->settings = array( ‘api_email’ => ”, ‘api_password’ => ”, ‘email_for_notification’ => $this->EE->config->item(‘webmaster_email’), ‘trigger_field’ => ”, ‘trigger_value’ => ‘y’, ‘sms_number_field’ => ”, ‘html_email_content’ => array(‘t’, ‘t’, ”), ‘text_email_content’ => array(‘t’, ‘t’, ”) );

    $hooks = array(
        array(
            'hook'        => 'freeform_module_insert_begin',
            'method'    => 'freeform_module_insert_begin',
            'priority'    => 10
        )
    );

    foreach ($hooks AS $hook)
    {
        $this->EE->db->insert(
            'extensions',
            array(
                'class'        => __CLASS__,
                'enabled'    => 'n',
                'hook'        => $hook['hook'],
                'method'    => $hook['method'],
                'priority'    => $hook['priority'],
                'settings'    => serialize($this->settings),
                'version'    => $this->version
            )
        );
    }

}[/code]
       

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.