添加表单动作 [英] Add form action

查看:53
本文介绍了添加表单动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我再次提交要转到index.php?page = servers时,我正在尝试制作表格,但是当我提交表单重定向时,它是index.php?但实际上是index.php?page = servers该如何解决呢?

I am trying to make when i submit to go again to index.php?page=servers but when i submit the form redirect is index.php? but in action is index.php?page=servers how can i fix this ?

<form class="form-horizontal" action="index.php?page=servers">
<fieldset>
<legend>Add server</legend>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">IP</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="ipserver" placeholder="IP Adress">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-lg-2 control-label">Port</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="portserver" placeholder="Port">
</div>
</div>
<div class="form-group">
<label for="select" class="col-lg-2 control-label">Type</label>
<div class="col-lg-10">
<select class="form-control" id="select">
<option>Half-Life (Counter-Stricke)</option>
<option>Minecraft</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button class="btn btn-default">Cancel</button>
<button type="submit" id="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>

和php

if(!empty($_POST['submit'])){
$ip_server = $_POST['ipserver'];
$port_server = $_POST['portserver'];
if ($ip_server == NULL || $port_server == NULL){
echo 'Моля попълнете всички полета.';
}else{
$type = "halflife";
$zone = 0;
$disabled = 0;
$status = 1;
$sql = ("INSERT INTO `lgsl` (type, ip, c_port, q_port, zone, disabled, status) VALUES ('$type', '$ip_server', '$port_server', '$port_server', '$zone', '$disabled', '$status')");
$result = mysql_query($sql);
echo 'Сървъра е успешно добавен!';
}
}

推荐答案

什么表单的默认方法是什么?

您需要向form标记添加一个属性,以根据您的代码将其转换为POST.

You need to add an attribute to the form tag to turn it into POST based on your code.

<form method="POST">

$ _POST与$ _SERVER ['REQUEST_METHOD'] =='POST'

要验证请求,请使用:

if( $_SERVER["REQUEST_METHOD"] == "POST" ) // or GET, if appropriate

如果您打算使用GET,则可以添加一个隐藏的元素,其名称为"page",值为"servers".

If you had intended to use GET, you could add a hidden element with the name "page" and the value "servers".

 <input type="hidden" name="page" value="servers" />

这篇关于添加表单动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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