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

Fieldtype development - strange entities conversion

Development and Programming

stephenfrank's avatar
stephenfrank
12 posts
15 years ago
stephenfrank's avatar stephenfrank

Hi,

I’m stumped on this one… hope I’m not being daft.

This custom field works exactly as I expect it should. It displays a textarea, I insert some HTML and text, save it, no worries.

class Test_field_ft extends EE_Fieldtype {

    var $info = array(
        'name'        => 'Test Field',
        'version'    => '1.0'
    );
    
    function Test_field_ft()
    {
        parent::EE_Fieldtype();
    }
    
    // --------------------------------------------------------------------
    
    function display_field($data)
    {
        return form_textarea(array(
            'name'    => $this->field_name,
            'id'    => $this->field_id,
            'value'    => $data
        ));
    }
    
    function save($data)
    {
        return $data;
    }
}

However I would like some array type fields like “field_id_7[content]”:

class Test_field_ft extends EE_Fieldtype {

    var $info = array(
        'name'        => 'Test Field',
        'version'    => '1.0'
    );
    
    function Test_field_ft()
    {
        parent::EE_Fieldtype();
    }
    
    // --------------------------------------------------------------------
    
    function display_field($data)
    {
        return form_textarea(array(
            'name'    => $this->field_name."[content]",
            'id'    => $this->field_id,
            'value'    => $data
        ));
    }
    
    function save($data)
    {
        return $data['content'];
    }
}

Now when I save my data

and go back to the publish page it has been converted to entities

&<p></p>

Am I missing something blatant? Any help would be appreciated as its killing me 😛

Update: I’m working around this with “html_entity_decode”… though I don’t think this is the right route to take.

function display_field($data)
    {
        return form_textarea(array(
            'name'    => $this->field_name."[content]",
            'id'    => $this->field_id,
            'value'    => html_entity_decode($data)
        ));
    }
       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

base64_encode your data before you save it and base64_decode it when you get it back from the database.

       
stephenfrank's avatar
stephenfrank
12 posts
15 years ago
stephenfrank's avatar stephenfrank

Thanks, I’ll give base64 a shot to see how that works but I don’t think it’s going to be an ideal solution for this instance because it won’t be searcheable in mysql… hrmmm.

Html-decoding the entities has been working out for me so far (at least no corrupt data yet) until I tried the feature where autosaved data is reloaded to the publish page… BAAAP (annoying buzzer sound) - all the data was reloaded but as entities.

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

yeah I had similar frustrations when developing the S3 uploader fieldtype. I assumed EE2 would save and load data like EE1 does because I didn’t see any documentation to the contrary… no such luck.

       
Manuel Payano's avatar
Manuel Payano
144 posts
15 years ago
Manuel Payano's avatar Manuel Payano

stephenfrank,

How is the text saved in your DB? As entities?

       
stephenfrank's avatar
stephenfrank
12 posts
15 years ago
stephenfrank's avatar stephenfrank

@ender: Glad I’m not the only one.

@DevDemon: Good question, the original characters are retained (ie. not as entities).

Just as they’re reloaded into the publish page they get turned into entities (I spent a lot of time pouring over EE core to figure this out but couldn’t come up with anything). It’s especially painful when working with serialized arrays as it corrupts the whole array (quotes get turned to & quote ; etc).

Anywho. I didn’t have any time to look at this today (Monday madness here), maybe I’ll get back to the fieldtype groove this weekend.

       

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.