提交表格给自己

max*_*ax_ 2 html javascript php

目前,我有一个带有输入(文本)和按钮的表单来提交表单.

表单将发布到"submit.php".我希望将表单发布到与表单相同的页面.

我怎样才能做到这一点?

<form action="submit.php" method="POST">
    <input type="text" class="emailField" placeholder="email address" name="email" />
    <button type="submit">
        <div class="submit" />
    </button>
</form>
Run Code Online (Sandbox Code Playgroud)

submit.php

<?php
    mysql_connect('localhost', '', '') or die('unable to connect');
    mysql_select_db('') or die('unable to select db');
    $query = mysql_query("");
    if (mysql_num_rows($query) > 0) {
        exit("You have already subscribed!");
    }
    else {
        mysql_query("") or die(mysql_error());
        exit("You have successfully subscribed!");
    }

?>
Run Code Online (Sandbox Code Playgroud)

Tre*_*non 6

我想你在这里有几个选择.

将表格提交给自己

<?php
    if('POST' == $_SERVER['REQUEST_METHOD']) {
        // process the form here
    }
?>
<form action="" method="POST">
    <input type="text" class="emailField" placeholder="email address" name="email" />
    <button type="submit">
        <div class="submit" />
    </button>
</form>
Run Code Online (Sandbox Code Playgroud)

重定向回到表单

submit.php在您要显示表单的位置添加类似的内容.

<?php
    header('Location: http://example.org/form.php');
    exit;
?>
Run Code Online (Sandbox Code Playgroud)

  • 你甚至不需要指定action ="".只是跳过那一部分,因为默认**本身就是**. (2认同)