-1

通过php头代码预览后,我不想重置输入框?谢谢。这是我的简化代码:

#php Code 
if($_POST['pre']){

    $tag = $_POST['tag'];
    $link = $_POST['link'];
    $img = $_POST['img'];
    $exp = $_POST['exp'];
    $alt = $_POST['alt'];
    if ( $tag == '' or $img == '' or $alt==''){

    }
    else{
    $_SESSION['pre'] = "<a href=" ;
    $_SESSION['pre'] .= "\"$link\"><img src=";
    $_SESSION['pre'] .= "\"$img\" alt=\"$alt\" ></a>";
    header("location: add_adv.php?show=on");
    }
}

html代码

<table>
<tr><td id="title"><p>add</p></td></tr>
<tr><td></td></tr>
    <tr>
      <td><form name="form2" method="post" action="">
        <table>
          <tr>
            <td><input type="text" name="tag" id="tag" /> </td>
            <td>tag</td>
          </tr>
          <tr>
            <td><input type="text" size="30" name="img" id="img" /></td>
            <td>picture</td>
          </tr>
          <tr>
            <td><input type="text" size="30" name="link" id="link" /></td>
            <td>link</td>
          </tr>
          <tr>
            <td><input type="text" size="30" name="alt" id="alt" /></td>
            <td>alternative</td>
          </tr>
          <tr>
            <td><input type="text" size="30" name="exp" id="exp" /></td>
            <td>Expire</td>
          </tr>
          <tr>
            <td><input name="pre" type="submit" class="sub" id="pre" value="Preview">
              <input type="submit" name="add_adv" class="sub" id="add_adv" value="اضافه" /></td>
            <td></td>
          </tr>
    </table>
      </form>
</td>
    </tr>
  </table>
4

3 回答 3

4

您必须为所有输入框赋予一个与之前提交的值相等的值属性。

<td><input type="text" size="30" name="exp" id="exp" value="<?=$exp?>" /></td>
<td>Expire</td>
于 2011-08-24T00:56:59.487 回答
1
// make public
$tag = $link = $img = $exp = $alt = null;

if($_POST['pre']){

    $tag = $_POST['tag'];
    $link = $_POST['link'];
    $img = $_POST['img'];
    $exp = $_POST['exp'];
    $alt = $_POST['alt'];
    if ( $tag == '' or $img == '' or $alt==''){

    }
    else{
    $_SESSION['pre'] = "<a href=" ;
    $_SESSION['pre'] .= "\"$link\"><img src=";
    $_SESSION['pre'] .= "\"$img\" alt=\"$alt\" ></a>";
    header("location: add_adv.php?show=on");
    }
}
于 2011-08-24T01:03:44.533 回答
0

非常简单的方法

在页面底部添加以下脚本

<script src="https://cdn.jsdelivr.net/gh/akjpro/form-anticlear/base.js"></script>

然后将“form-anticlear”类添加到您的表单中

<form class="form-anticlear">
   <input type="text" name="myText">
</form>

访问高级选项:https ://github.com/akjpro/form-anticlear

于 2021-02-13T09:48:38.290 回答