douyinzha5820 2014-05-20 12:47
浏览 186

如何从下拉列表中获取选定的值并使用它来显示另一个表单?

I am new to PHP, Yii-framework and web programming in general.

So I have some difficulties in writing simple registration form.

I have tables Persons, Categories, Properties, CategoryProperties, PropertyValues:

Persons ( name, category_id)
Categories(category_id, category_name)
Properties(propety_id, property_name)
CategoryProperties(category_id, property_id)
PropertyValues(property_id, category_id, person_id, some_value)

For example, category_name = 'teacher', property='work experience', some_value='15'.

Depending on which category was selected we should display block with properties matching that category.

How to get selected value from dropdown list (Categories) and use it to display another form which depends on that value and other database table?

So far I have only this

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'login-form',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>
<div class="row">
        <?php echo $form->labelEx($model,'name'); ?>
        <?php echo $form->textField($model,'name'); ?>
        <?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
    <?php echo $form->labelEx($model,'category'); ?>
    <?php 
    echo $form->dropDownList($model,'category', 
    Categories::model()->getAssocList(),  array('empty'=>'Select category')?>
    <?php echo $form->error($model,'category'); ?>
</div>
<div class="row buttons">
    <?php echo CHtml::submitButton('AddReader'); ?>
</div>

<?php $this->endWidget(); ?>
</div><!-- form -->
  • 写回答

1条回答 默认 最新

  • dongsui3297 2014-05-20 13:04
    关注

    Not sure if I got it right, are you trying to update a second combo once the first was modified using php? if so, you can't.

    You have to use JavaScript and if you are using a database, probably Ajax.

    Remember PHP is a server side language, you have to post your form again to update it. That's why you should use javascript, that runs on the browser.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!