如何在提交后保留表单的值

时间:2015-08-12 10:13:28

标签: php form-submit

<?php
    $member_results = oci_parse($conn, "SELECT distinct(M.ID), M.NAME FROM .............");
    oci_execute($member_results);
?>

<form action="" method="post" id="report-page-form-form" class="clearfix"  onclick="changeValue();">
    <div class="member-drop-report">
        <label>Filter by Member:</label>
        <select name="memberorg">
            <option value="0">Any Member Organization</option>
            <?php 
                while( $data = oci_fetch_assoc($member_results) ){ 
                    echo "<option value=\" $data['ID'] \">$data['NAME'] </option>";
                } 
             ?>
        </select> 
    </div>
    <div class="date-input-report clearfix">
        <label>Start Date:</label><input type="text" name="start-date"  id="start" placeholder="YYYY-MM-DD" readonly>
    </div>
    <div class="date-input-report clearfix">
        <label>End Date:</label><input type="text" name="end-date"  id="end" placeholder="YYYY-MM-DD" readonly>
    </div>
    <input class="form-submit" type="submit" value="Filter">
</form>

我正在使用此表单提交数据。表格工作正常。但是这些值会在提交时清除。提交后如何保留表单中提交的值?我在开始和结束日期使用jQuery日期选择器。

2 个答案:

答案 0 :(得分:0)

在代码中添加以下内容:

$start_date = (isset($_POST['start-date']) ? $_POST['start-date'] : '');

在HTML中:

<input type="text" name="start-date"  id="start"  value="<?=start_date?>" placeholder="YYYY-MM-DD" readonly>

答案 1 :(得分:0)

<form action="" method="post" id="report-page-form-form" class="clearfix"  onclick="changeValue();">
        <div class="member-drop-report">
        <label>Filter by Member:</label>
        <select name="memberorg">
        <option value="0">Any Member Organization</option>
        <?php while( $data = oci_fetch_assoc($member_results) ){ ?>
          <option <?php if ($_POST['memberorg'] == $data['ID']) { ?> selected="true" <?php } ?> value="<?php echo $data['ID']; ?>"><?php echo $data['NAME']; ?></option>
        <?php } ?>
        </select> 
        </div>
        <?php 
        $start_date = (isset($_POST['start-date']) ? 'value='.$_POST['start-date'] : 'placeholder="YYYY-MM-DD"');
        $end_date = (isset($_POST['end-date']) ? 'value='.$_POST['end-date'] : 'placeholder="YYYY-MM-DD"');
        ?>
        <div class="date-input-report clearfix"><label>Start Date:</label><input type="text" name="start-date" <?php echo $start_date; ?> id="start"  readonly></div>
        <div class="date-input-report clearfix"><label>End Date:</label><input type="text" name="end-date"  id="end" <?php echo $end_date; ?> readonly></div>
        <input class="form-submit" type="submit" value="Filter">
</form>