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.

    评论

报告相同问题?

悬赏问题

  • ¥15 用lstm来预测股票价格
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上