We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Addons, Api, Runway

Parse Problems - PerchXMLTag's / PerchAPI_Template

Drew, I have noticed when using $Template->find_all_tags() some attributes may be missing, and the Tag is returned broken (or incomplete) I have included some actual examples of when this happens.

form template

<perch:form id="contact" method="post" app="perch_forms">

    <perch:content id="intro" type="textarea" label="Intro" textile="true" editor="markitup" size="m" />

    <div>
        <perch:label for="name">Name</perch:label>
        <perch:input type="text" id="name" required="true" label="Name" />
        <perch:error for="name" type="required">Please add your name</perch:error>
    </div>

   <div>
        <perch:label for="state">State</perch:label>
        <perch:input type="select" id="state" label="State" options="<perch:content id="stateOptions" />" />
    </div>

    <div>
        <perch:input type="submit" id="submit" value="Send" />
    </div>

    <perch:success>
        <perch:content id="success" type="textarea" label="Thank you message" textile="true" editor="markitup" />
    </perch:success>
</perch:form>

In Runtime

$tags = $Template->find_all_tags('input')

here is the output:


Array
(
    [0] => PerchXMLTag Object
        (
            [attributes] => Array
                (
                    [type] => text
                    [id] => name
                    [required] => true
                    [label] => Name
                )

            [data_attributes] => Array
                (
                )

            [tag:PerchXMLTag:private] => <perch:input type="text" id="name" required="true" label="Name" />
        )

    [1] => PerchXMLTag Object
        (
            [attributes] => Array
                (
                    [type] => select
                    [id] => state
                    [label] => State
                    [options] => <perch:content id=
                )

            [data_attributes] => Array
                (
                )

            [tag:PerchXMLTag:private] => <perch:input type="select" id="state" label="State" options="<perch:content id="stateOptions" />
        )

    [2] => PerchXMLTag Object
        (
            [attributes] => Array
                (
                    [type] => submit
                    [id] => submit
                    [value] => Send
                )

            [data_attributes] => Array
                (
                )

            [tag:PerchXMLTag:private] => <perch:input type="submit" id="submit" value="Send" />
        )

)

If you look at [1] in the Tags array the [tag] is missing the last double-quote on the options attribute and the closing on the input tag.

I know this is caused by the <perch:content /> tag in the options attribute. If the nested tag isn't the final attribute, then even more attributes are missing.

I am thinking the parsing may need additional regex... I am not sure. Of course if the nested tag is removed then everything works as expected.

In the Perch_Forms app, the Tags are saved with submitted forms, and if you try to template back the data relying on the saved tag data, sometimes it fails on these broken tags.

I am doing a similar technique in my custom app and these kinds of forms keep popping up.

Robert Ketter

Robert Ketter 103 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Nesting tags only works when you're relying on two phase parsing. When displaying a template that's fine, as the content tag gets parsed in the first phase, and the form then get parsed in the later second phase (which is the one that always happens at runtime).

It's sort of a hack that is taking advantage of the way the parsing occurs - it's only suitable for outputting forms.

It's sort of a hack that is taking advantage of the way the parsing occurs - it's only suitable for outputting forms.

I suspected this might be the case...

I have to say, there are a lot of people taking advantage of this too. I see it all the time in client sites.

I created a way to nest tags in my app which adds what I am calling a sub-namespace (perch:input:subNamespace) and I parse these in my app runtime's. This adjustment allows the forms to function in other apps without creating the "hacking" results of nested tags.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's fine to use - we use it ourselves - but only for output.