Search

I’m using Mr Dunn’s excellent Form Controls XSL in my current project. I’ve added a (very simple) method of including inline validation for fields.

<!--
Name: form:validation-inline
Description: Renders inline validation message for the specified field
Returns: HTML <span> element
Parameters:
* `error` (XPath): XPath expression to the specific error element
-->
<xsl:template name="form:validation-inline">
    <xsl:param name="event" select="$form:event"/>
    <xsl:param name="error"/>

    <xsl:element name="span" use-attribute-sets="validation-inline">
        <xsl:value-of select="$error/@message"/>
    </xsl:element>
</xsl:template>

<xsl:attribute-set name="validation-inline">
  <xsl:attribute name="class">validation-inline</xsl:attribute>
</xsl:attribute-set>

I call it like so:

<xsl:call-template name="form:validation-inline">
  <xsl:with-param name="error" select="$form:event/description"/>
</xsl:call-template>

I’m certainly no XSL ninja, and there’s probably a cleaner way to do this. For starters, I’d like to not have to pass ‘$form:event’ in each time. Can anyone show me how to do this?

Nice. Glad to see someone using Form Controls. It’s been a while since I’ve had a chance to play around with this. See if you can glean anything from my experiments with my Form Builder ensemble. I was playing around with combining Section Schemas and Form Controls to dynamically rebuild the Symphony admin as front end forms.

It’s so nice to see others having the same ideas. I’ve also noted in the back of my mind to make some combination of Section Schemas and Form Controls. That is, I’ve already experimented with some simple templates for my needs thus far:

<xsl:template match="section-schema/*[@type = 'input'] | section-schema/*[@type = 'date']">
    <xsl:variable name="field" select="name()" />

    <div>
        <label for="fields-{$field}">
            <xsl:value-of select="$lstrings/label[@key = $field]" />
        </label>
        <xsl:call-template name="form:input">
            <xsl:with-param name="handle" select="$field" />
        </xsl:call-template>
    </div>
</xsl:template>

<xsl:template match="section-schema/*[@type = 'textarea']">
    <xsl:variable name="field" select="name()" />

    <div>
        <label for="fields-{$field}">
            <xsl:value-of select="$lstrings/label[@key = $field]" />
        </label>
        <xsl:call-template name="form:textarea">
            <xsl:with-param name="handle" select="$field" />
            <xsl:with-param name="rows" select="size" />
            <xsl:with-param name="cols" select="'50'" />
        </xsl:call-template>
    </div>
</xsl:template>

(The $lstrings variable contains language strings dynamically loaded based on $url-language from the Language Redirect extension). But there’s a lot of improvement to be done in simplifying the invocation of this, and further combining validation. In our open source webapp framework, Kolibri, we have some cool meta-XSLT I wrote to generate form fields with validation errors from models. So I’m going to try loan some ideas from that for Symphony projects as well.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details