提交表格给自己 [英] submit form to self

查看:83
本文介绍了提交表格给自己的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

表单发布到'submit.php'。我希望表单发布到同一页面。



我该怎么做?

 < form action =submit.phpmethod =POST> 
< input type =textclass =emailFieldplaceholder =email addressname =email/>
< button type =submit>
< div class =submit/>
< / button>
< / form>

submit.php

 <?php 
mysql_connect('localhost','','')或die('无法连接');
mysql_select_db('')或死('无法选择db');
$ query = mysql_query();
if(mysql_num_rows($ query)> 0){
exit(您已订阅!);
}
else {
mysql_query()或die(mysql_error());
exit(您已成功订阅!);
}

?>


解决方案

我认为您在这里有几个选项。



将表单提交到自身上

 <?php 
if('POST'== $ _SERVER ['REQUEST_METHOD']){
//在此处理表单
}
?>
< form action =method =POST>
< input type =textclass =emailFieldplaceholder =email addressname =email/>
< button type =submit>
< div class =submit/>
< / button>
< / form>



重新导向到表格



添加在 submit.php 中你想显示表单的地方。

 <?php 
header('Location:http://example.org/form.php');
出口;
?>


At the moment, I have a form with an input (text) and a button to submit the form.

The form is posted to 'submit.php'. I would like the form posted to same page as the form.

How can I do this?

<form action="submit.php" method="POST">
    <input type="text" class="emailField" placeholder="email address" name="email" />
    <button type="submit">
        <div class="submit" />
    </button>
</form>

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!");
    }

?>

解决方案

I think you have a couple of options here.

Submit the form onto itself

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

Redirect back to the form

Add something like this in submit.php where you want to show the form.

<?php
    header('Location: http://example.org/form.php');
    exit;
?>

这篇关于提交表格给自己的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆