提交后不要重置表单值

发布于 2024-12-01 02:49:30 字数 2022 浏览 0 评论 0原文

通过 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>

After giving a preview by php header code, I want to not reset the input boxes? Thanks.
This is my simplified code:

#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 Code

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

征棹 2024-12-08 02:49:31

您必须为所有输入框指定一个等于先前提交的值的值属性。

<td><input type="text" size="30" name="exp" id="exp" value="<?=$exp?>" /></td>
<td>Expire</td>

You have to give all the input boxes a value attribute equal to the previously submitted value.

<td><input type="text" size="30" name="exp" id="exp" value="<?=$exp?>" /></td>
<td>Expire</td>
戏蝶舞 2024-12-08 02:49:31
// 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");
    }
}
// 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");
    }
}
最初的梦 2024-12-08 02:49:31

非常简单的方法

在页面底部添加以下脚本

<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

Very simple method

Add below script in bottom of your page

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

Then add 'form-anticlear' class to your form

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

Visit for advanced options : https://github.com/akjpro/form-anticlear

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文