简体   繁体   English

Yii2:如何获取默认表单名称?

[英]Yii2: How to get default form name?

I have a view with a simple form: 我有一个简单的形式的观点:

<?php $form = ActiveForm::begin(); ?>
...
<?php ActiveForm::end(); ?>

I need to know the default name of the form. 我需要知道表单的默认名称。 I tried using JavaScript, jQuery or even PHP but I don't know ho to get it. 我尝试使用JavaScript,jQuery甚至PHP,但我不知道该如何获得它。

if the active form is created by gii by default Yii2 don't assign name but assign id tipically 如果活动表单是由gii默认创建的Yii2,请不要分配名称,而要分配ID

id="w0" 

If you need you could assign values using options 如果需要,您可以使用选项分配值

  $form = ActiveForm::begin([
    'id' => 'your-id-form',
   'options' => ['class' => 'form-horizontal', 'name' => 'your-name],
  ]) ?>

http://www.yiiframework.com/doc-2.0/yii-bootstrap-activeform.html http://www.yiiframework.com/doc-2.0/yii-bootstrap-activeform.html

http://www.yiiframework.com/doc-2.0/guide-input-forms.html http://www.yiiframework.com/doc-2.0/guide-input-forms.html

在jQuery中,您可以执行此操作

$('form').prop('id');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM