ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Parsing an EE tag with PHP

May 16, 2011 12:10pm

Subscribe [2]
  • #1 / May 16, 2011 12:10pm

    RyanHavoc

    14 posts

    I’m putting together a contact form with FreeForm and I have a subject field as a select input that lists various services the company provides.

    I want to make this list of services editable through ExpressionEngine so I’ve created a Global Variable ({contact-subjects}) with this inside it:

    Piano Restoration (.(JavaScript must be enabled to view this email address)),
    Piano Removal (.(JavaScript must be enabled to view this email address)),
    Piano Tuning (.(JavaScript must be enabled to view this email address)),
    Piano Hire (.(JavaScript must be enabled to view this email address))

    The idea being that I’ll parse this variable with PHP and construct the select input and use the email address in the curly brackets as the recipients for FreeForm.

    The problem is for some reason I cannot explode the string…

    I’ve started with this:

    $contact_subjects = "{contact-subjects}";
    
    $parsed_subjects = explode(",", $contact_subjects);
    
    echo '<pre>';
    print_r($parsed_subjects);
    echo '</pre><p>‘;
    </pre>

    And I get this:

    Array
    (
        [0] => Piano Restoration (.(JavaScript must be enabled to view this email address)),
    Piano Removal (.(JavaScript must be enabled to view this email address)),
    Piano Tuning (.(JavaScript must be enabled to view this email address)),
    Piano Hire (.(JavaScript must be enabled to view this email address))
    )

    It hasn’t parsed the string…

    If I do this:

    $contact_subjects = "Piano Restoration (.(JavaScript must be enabled to view this email address)),
    Piano Removal (.(JavaScript must be enabled to view this email address)),
    Piano Tuning (.(JavaScript must be enabled to view this email address)),
    Piano Hire (.(JavaScript must be enabled to view this email address))";
    
    $parsed_subjects = explode(",", $contact_subjects);
    
    echo '<pre>';
    print_r($parsed_subjects);
    echo '</pre><p>‘;
    </pre>

    I get what I would expect:

    Array
    (
        [0] => Piano Restoration (.(JavaScript must be enabled to view this email address))
        [1] => 
    Piano Removal (.(JavaScript must be enabled to view this email address))
        [2] => 
    Piano Tuning (.(JavaScript must be enabled to view this email address))
        [3] => 
    Piano Hire (.(JavaScript must be enabled to view this email address))
    )

    Has anyone else had this kind of problem?

  • #2 / May 17, 2011 8:47am

    Kernon

    173 posts

    I can confirm that this happens on my installation as well, and I’m curious why.  Obviously, a global variable is in certain aspects unique (not parsed early, etc.) but it’s not obvious to me why this would affect the PHP operations.

    A possible work-around, though, would be to put the option list into a particular channel (weblog) entry.  Depending upon who is supposed to be able to change the options, an entry might be a better choice—someone with access to entries but not templates.

    Another alternative is a template variable (if this applies to one or a only few templates).

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases