Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

OpenTag Helper - allow "itemprop", "itemscope" and "itemtype" for microdata as attributes #179

Open
koseduhemak opened this issue Sep 27, 2017 · 6 comments

Comments

@koseduhemak
Copy link

I tried to add some microdata to my form:

$form->setAttributes([
    'itemprop' => 'potentialAction',
    'itemscope' => 'itemscope',
    'itemtype' => 'http://schema.org/SearchAction'
]);

This does not work, as the specified attributes are not added if I render the form's open tag:

$this->form()->openTag($form);

Any workaround to get this specific attributes working?

@jcaillot
Copy link

just my 50 cents on this
you may want to override
\Zend\Form\View\Helper\AbstractHelper::prepareAttributes

@froschdesign
Copy link
Member

@koseduhemak

Any workaround to get this specific attributes working?

The fastest way:

<?= $this->form()->openTag($form) ?>
<div itemprop="potentialAction">

@jcaillot

you may want to override
\Zend\Form\View\Helper\AbstractHelper::prepareAttributes

Why? I think only the elements which wraps other elements should have these universal attributes. (e.g. form and label)

@koseduhemak
Copy link
Author

@froschdesign
Thank you, used your workaround.

Another problem occurs at the input field:
<input itemprop="query-input" type="text" name="search_term_string" required="true" />
I know I can wrap that element in a div too. But I think it must be added to the input field itself (because it is actually the query-input for my search engine). The complete desired markup I try to reproduce is from Google and is required to get a search box in the search results of Google:

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

for more information: https://developers.google.com/search/docs/data-types/sitelinks-searchbox

@froschdesign
Copy link
Member

@koseduhemak
Good catch! Then we must extend the $validGlobalAttributes.

protected $validGlobalAttributes = [

@jcaillot
Copy link

see #50

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at laminas/laminas-form#10.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants