php下拉框 复原 提交之后_PHP如何从下拉菜单中保留所选选项,以便在提交时保持选中状态?...

I have:

General Question

Company Information

Customer Issue

Supplier Issue

Request For Quote

Other

for the drop down. And when the form is submitted, It goes to a validation page. If it has errors the form keeps the original content the user put in. I have it working for all of the input fields and textarea's, but how could I do this with a drop down?

I have the input fields staying by using:

$name = $_REQUEST["name"];

and in the form that shows up again, there is (ignore the fact that it is in a table):

Name:*

So, any ideas for drop downs?

解决方案

You need to add the "selected" attribute to the appropriate option. I believe you also need to specify the value attribute for each option. I don't know exactly how you are generating that list, but maybe this will help:

$options = array( 1=>'General Question', 'Company Information', 'Customer Issue', 'Supplier Issue', 'Supplier Issue', 'Request For Quote', 'Other' );

$topic = $_REQUEST['topic']; // the topic name would now be $options[$topic]

// other PHP etc...

?>

<?php foreach ( $options as $i=>$opt ) : ?>

><?php echo $opt ?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值