php表单 - 重新加载提交

时间:2014-12-09 11:18:58

标签: php form-submit reload

我需要在网站上编辑其他人的代码(该人无法访问),我对PHP没有太多经验。在此表单中,此表单将重定向到提交的上一页。我必须更改它才能重新加载当前页面。我已经多次尝试更改表单的操作字段,但它们都导致空白页面或已经重定向到的页面。有人可以在这里分享一些知识吗?

<div id="tab-general" class="tab-content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <table>
          <tr>
            <td><span class="required">*</span>&nbsp;<?php echo $entry_title; ?></td>
            <td><input type="text" value="<?php echo $title; ?>" name="title" id="title" /><br />
            <?php if ($error_title) { ?>
              <span class="error"><?php echo $error_title; ?></span>
            <?php } ?></td>
          </tr>
          <tr>
            <td><span class="required">*</span>&nbsp;<?php echo $entry_name; ?></td>
            <td><input type="text" value="<?php echo $name; ?>" name="name" id="name" /><br />
            <?php if ($error_name) { ?>
              <span class="error"><?php echo $error_name; ?></span>
            <?php } ?></td>
          </tr>
          <tr>
            <td><span class="required">*</span>&nbsp;<?php echo $entry_email; ?></td>
            <td><input type="text" value="<?php echo $email; ?>" name="email" id="email" /><br />
            <?php if ($error_email) { ?>
              <span class="error"><?php echo $error_email; ?></span>
            <?php } ?></td>
          </tr>
          <tr>
            <td><span class="required">*</span>&nbsp;<?php echo $entry_end_date; ?></td>
            <td><input type="text" value="<?php echo $end_date; ?>" name="end_date" id="end_date" /><br />
            <?php if ($error_end_date) { ?>
              <span class="error"><?php echo $error_end_date; ?></span>
            <?php } ?></td>
          </tr>
          <tr>
            <td><?php echo $entry_type; ?></td>
            <td><select name="type" id="type" class="type_list">
              <?php if ($type) { ?>
                <option value="1" selected="selected"><?php echo $text_private; ?></option>
                <option value="0"><?php echo $text_public; ?></option>
                <?php } else { ?>
                  <option value="1"><?php echo $text_private; ?></option>
                  <option value="0" selected="selected"><?php echo $text_public; ?></option>
                <?php } ?>
            </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_status; ?></td>
            <td><select name="status">
            <?php if ($status) { ?>
              <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
              <option value="0"><?php echo $text_disabled; ?></option>
              <?php } else { ?>
                <option value="1"><?php echo $text_enabled; ?></option>
                <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
              <?php } ?>
            </select></td>
          </tr>
          <tr>
            <td><br /><h2><?php echo $text_invitees; ?></h2></td>
            <td></td>
          </tr>
        </table>
        <table id="attendee" class="list">
          <thead>
            <tr>
              <td class="left"><?php echo $entry_att_name; ?></td>
              <td class="right"><?php echo $entry_att_email; ?></td>
              <td></td>
            </tr>
          </thead>
          <tfoot>
            <tr>
              <td colspan="2"></td>
              <td class="left"><a onclick="addAttendee();" class="button"><?php echo $button_add; ?></a></td>
            </tr>
          </tfoot>
          <?php $attendee_row = 0; ?>
          <?php if ($attendees) { ?>
            <?php foreach ($attendees as $attendee) { ?>
            <tbody id="attendee-row<?php echo $attendee_row; ?>">
              <tr>
                <td class="left"><input type="text" name="attendee[<?php echo $attendee_row; ?>][name]" value="<?php echo $attendee['name']; ?>" size="18" />
                <?php if (isset($error_name_attendee[$attendee_row])) { ?>
                  <span class="error"><?php echo $error_name_attendee[$attendee_row]; ?></span>
                <?php } ?>
                </td>
                <td class="right"><input type="text" name="attendee[<?php echo $attendee_row; ?>][email]" value="<?php echo $attendee['email']; ?>" size="18" />
                <?php if (isset($error_email_attendee[$attendee_row])) { ?>
                  <span class="error"><?php echo $error_email_attendee[$attendee_row]; ?></span>
                <?php } ?>
                </td>
                <td class="left"><a onclick="$('#attendee-row<?php echo $attendee_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a>
                </td>
              </tr>
            </tbody>
          <?php $attendee_row++; ?>
            <?php } ?>
            <?php } ?>
        </table>
      <div class="buttons"><div class="left">
        <a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a></div><div class="right"><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a>
      </div></div>
  </div>

检查$ action变量的内容后,结果表明它保存了当前页面的链接。它应该重新加载页面,但它没有。

示例:这是链接

localhost/index.php?route=account/projects/editProject&project_id=1&akey=98c27892d1e2a13c0dfb9086539f8275

并存储在$ action变量中。相反,方向​​是链接

localhost/index.php?route=account/projects

3 个答案:

答案 0 :(得分:2)

确保您的操作的路径等于您的页面路径,然后它将提交您的表单值并保留在同一页面上 如果此页面的路径类似于例如/home/index.php 那么

<form action="/home/index.php" method="post" enctype="multipart/form-data" id="form">

如果您从$action变量获取路径,请尝试echo $action;以确保您当前页面的路径相同

答案 1 :(得分:0)

第二行的$ action变量应该会导致您要重新加载的页面。

答案 2 :(得分:0)

如果您希望表单提交到当前页面,只需从表单标记中删除action属性即可。但是,您必须检查是否发生了数据子目录,以防止呈现表单或重新提交表单,如下所示:

<?php if (isset($_POST['title']) && $_POST['title'] != ''): ?>

//Perform form data processing 

<?php else: ?>
// Your form code

<?php endif; ?>