gpt4 book ai didi

css - 将 css 类添加到表单(Yii 表单生成器)

转载 作者:太空宇宙 更新时间:2023-11-04 13:37:57 26 4
gpt4 key购买 nike

我们如何在 Yii form bui 创建的表单元素中添加 css class 或 id想象一下,我创建了一个表单,如下所示:

Controller :

public function actionRegistration()
{

$form = new CForm('application.views.user.registerForm');
$form['user']->model = new Users;
$form['profile']->model = new Profile;

if(isset($_POST['Users']))
{
$form['profile']->model->attributes = $_POST['Profile'];
$_POST['Users']['mobile'] = $_POST['Profile']['mobile'];
$form['user']->model->attributes = $_POST['Users'];

if($form->validate()) {
$user = $form['user']->model;
$profile = $form['profile']->model;
if($profile->save(false))
{
$user->profile_id = $profile->id;
$user->save(false);
}
}
else {
$errors = array_merge($form['profile']->model->errors, $form['user']->model->errors);
}
}

$this->render('registration', array('form'=>$form));
}

查看

    <?php echo $form->renderBegin(); ?>
<div class="row">
<div class="nine columns">
<div class="field">
<?php echo $form['profile']['fname']; ?>
</div>
<div class="field">
<?php echo $form['profile']['lname']; ?>
</div>
<div class="row">
<div class="eight columns">
<div class="field phone">
<?php echo $form['profile']['phone']; ?>
</div>
</div>
<div class="eight columns">
<div class="field mobile">
<?php echo $form['profile']['mobile']; ?>
</div>
</div>
</div>
<div class="row">
<div class="eight columns">
<div class="field password">
<?php echo $form['user']['pass']; ?>
</div>
</div>
</div>

<div class="field address email">
<input type="text" name="Users[email]" value="" placeholder="Email" class="text input">
</div>
</div>


</div>
<div class="row text-center margins">
<span class="medium warning btn">
<button type="submit"Submit</button>
</span>
</div>
<?php echo $form->renderEnd(); ?>

我想为由 $form->renderBegin() 函数生成的表单元素设置一个 id 或一个类。我不知道如何向表单添加任何 html 选项。请有人帮助我。

最佳答案

在 renderBegin 之前的 View 文件中对属性进行赋值:

<?php 
$form->attributes= array('id'=>'el123', 'class'=>'qwe');
echo $form->renderBegin(); ?>

关于css - 将 css 类添加到表单(Yii 表单生成器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22896614/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com