zend-form icon indicating copy to clipboard operation
zend-form copied to clipboard

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

Open koseduhemak opened this issue 8 years ago • 6 comments

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?

koseduhemak avatar Sep 27 '17 16:09 koseduhemak

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

jcaillot avatar Sep 27 '17 23:09 jcaillot

@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)

froschdesign avatar Sep 28 '17 06:09 froschdesign

@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

koseduhemak avatar Sep 28 '17 08:09 koseduhemak

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

https://github.com/zendframework/zend-form/blob/1e34504d29f36f870e72a4a5de0b6e5c85db310f/src/View/Helper/AbstractHelper.php#L90

froschdesign avatar Sep 28 '17 08:09 froschdesign

see #50

jcaillot avatar Jul 17 '18 13:07 jcaillot

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at https://github.com/laminas/laminas-form/issues/10.

weierophinney avatar Dec 31 '19 22:12 weierophinney