zendframework / zend-form

Form component from Zend Framework
BSD 3-Clause "New" or "Revised" License
69 stars 87 forks source link

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

Open koseduhemak opened 7 years ago

koseduhemak commented 7 years ago

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 commented 7 years ago

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

froschdesign commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

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

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

jcaillot commented 6 years ago

see #50

weierophinney commented 4 years ago

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.