dongpa3109 2013-11-17 20:29
浏览 60

PHP代码添加字段时添加多个字段而不重置下拉菜单

I am a newbee to PHP.

I am trying to develop a website which tracks the daily efforts of a team. The problem is I am stuck with the code at one point.

When I click on Add Event, the fields pop up keeping the values in the typing field as such and resetting the drop down values. Please help in resolving this.

    <?php
    echo('
    <form action="" method="POST">');
    $count = isset($_POST['count']) ? $_POST['count'] : 1;
    if($count > 11) $count = 11;
    ?>
    <table>
   <input type="hidden" name="count" value="<?php echo $count+1; ?>"/>

    <?php for($i = 0; $i < $count; $i++): 
    $val0 = isset($_POST['event'][$i]['0']) ? $_POST['event'][$i]['0'] : '';
    $val1 = isset($_POST['field'][$i]['1']) ? $_POST['field'][$i]['1'] : '';
    ?>
    <td><select name="event[<?php echo $i; ?>][1]" value="<?php echo $val1; ?>"/>
<option>Choose Event</option>
<option> Incident </option>
<option> Change </option>
<option> Complaint </option>
<option> Compliance </option>
<option> Transition </option>
<option> Appreciation </option>
<option> Disaster_Recovery </option></td>
    <td><input name="field[<?php echo $i; ?>][1]" value="<?php echo $val1; ?>"/></td>
    <?php endfor; ?>
    </table>
    <input type="submit" value="Add Event" />

This is just a sample, I need to add another drop down for each option listed above and also about 20 free text fields for the users to enter their data.

After all these are done, at one shot all these fields should go to the mysql table to their respective columns on submit.

Seems like, I am stuck up very badly. I got to complete this asap. Please help. - Thank you.

  • 写回答

1条回答 默认 最新

  • donglanzhan7151 2013-11-17 20:37
    关注

    I think I see a small error; you have event[$i][0] above and event[$i][1] below

    $val0 = isset($_POST['event'][$i]['0']) ? $_POST['event'][$i]['0'] : '';
    $val1 = isset($_POST['field'][$i]['1']) ? $_POST['field'][$i]['1'] : '';
    ?>
    <td><select name="event[<?php echo $i; ?>][1]" value="<?php echo $val1; ?>"/>

    so i would change that portion to this:

    $val0 = isset($_POST['event'][$i]['0']) ? $_POST['event'][$i]['0'] : '';
    $val1 = isset($_POST['field'][$i]['1']) ? $_POST['field'][$i]['1'] : '';
    ?>
    <td><select name="event[<?php echo $i; ?>]['0']" value="<?php echo $val0; ?>"/>

    (change the two 1's to 0's on the last line here). Although it seems kind of strange to have the form field names be array elements like this, does it work?

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度