问题
How do I add a value-ess attribute to the form tag?
I want to have:
<form data-abide >
according to: http://foundation.zurb.com/sites/docs/abide.html
I've tried
<?php $form = ActiveForm::begin(['id' => 'contact-form', 'options'=>['data-abide'=>'']]); ?>
but get output:
<form data-abide="ak8hvf-abide" >
回答1:
Try this:
'options'=>['data-abide'=>true]
Reference: In the framework helper BaseHtml.php file, find :
function renderTagAttributes
Where :
foreach ($attributes as $name => $value) {if (is_bool($value)) { if ($value) { $html .= " $name"; } } elseif...
...
elseif ($value !== null) { $html .= " $name=\"" . static::encode($value) . '"'; }
...
回答2:
It is actually behaving as expected - turns out it is the adide.js which adds the extra security token: https://github.com/yiisoft/yii2/issues/10532#issuecomment-169952232
Thanks everyone for help!
回答3:
For me, both 'data-abide'=>''
and 'data-abide'=>true
works fine...
Could it be something outdated? Can you try run a composer update
in your project?
来源:https://stackoverflow.com/questions/34667635/how-to-add-valueless-attribute-to-form-tag-using-yii2-activeform