Forum

Thread tagged as: Question, Forms

Adding an attribute to a Perch form tag

Is it possible to add more attributes to a perch form tag? I notice that Perch strips them out.

I would like to add some schema to a search form.

Here is an example of the schema markup:

<form itemprop="potentialAction" itemscope itemtype="https://schema.org/SearchAction">
        <meta itemprop="target" content="https://example.com/search?q={query}"/>
        <input itemprop="query-input" type="text" name="query"/>
        <input type="submit"/>
</form>

Source

Jay George

Jay George 2 points

  • 3 years ago

Jay,

You can add only data- and class attributes to perch:form, all others will be stripped away....

Thanks Robert.

So does that mean I can't use any schema markup on forms? Can you think of a work around?

I myself do not know a workaround except maybe a JS/data- swap. In other words, put the info in data- then use javascript to apply to the tag, but I have to think this would not work in the case of a search engine as they likely ignore the JS scripts anyway.

Sorry :(

I figured out that schema doesn't seem to care if the attributes are not directly on the form element. This seems to be recognised the same way on Google's Structured Data Testing Tool

<form>
    <div itemprop="potentialAction" itemscope itemtype="https://schema.org/SearchAction">
        <meta itemprop="target" content="https://example.com/search?q={query}"/>
        <input itemprop="query-input" type="text" name="query"/>
        <input type="submit"/>
    </div>
</form>

Jay,

I believe no matter the tag, perch strips away all attributes except data- and class. This is unconfirmed, but I feel near 100% on this.

Yep I think you're right.

I've just shifted the schema attributes to an element outside of a Perch tag and schema still treats it as valid, so problem solved I think.