How to add valueless attribute to <form> tag using yii2 ActiveForm

。_饼干妹妹 提交于 2019-12-24 16:25:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!