我的表单不起作用 当我提交表单时,名称例如昵称不起作用,它等于0 当我尝试isset它显示真实
if(isset($_POST['name'])) {echo 'name!';} else {echo 'no!';}
<form action="signup-form.php" method="post" class="form-horizontal" id="form-signup">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="name" class="form-control" id="name" placeholder="Name" name="name" />
</div>
</div>
<div class="form-group">
<label for="nickname" class="col-sm-2 control-label">Nickname</label>
<div class="col-sm-10">
<input type="nickname" class="form-control" id="nickname" placeholder="Nickname" name="nickname" />
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" placeholder="Email" name="email" />
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<div class="col-sm-5">
<input type="password" class="form-control" id="signup_password" placeholder="Password" name="password" />
</div>
<div class="col-sm-5">
<input type="password" class="form-control" id="confirm_password" placeholder="Confirm" name="confirm_password" />
</div>
</div>
<div class="row" style="margin-bottom:10px;">
<div class="col-sm-2"></div>
<div class="col-sm-10">
<script src='https://www.google.com/recaptcha/api.js'></script>
<?php
// Recaptcha
require_once(dirname(__FILE__)."/include/recaptchalib.php");
$publickey = "6LcTBw8TAAAAAOriZNY3CS7nukStq1WbcGRmprRR"; // You got this from the signup page.
echo recaptcha_get_html($publickey);
?>
</div>
</div>
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-10">
<input type="submit" class="btn btn-primary btn-sm" value="Signup">
</div>
</div>
</form>
答案 0 :(得分:1)
有些事情,你的HTML无效(虽然我不确定它是否会破坏它)请在输入字段中使用适当的类型值。对于名称和昵称,有效类型值为“text”,而不是“name”或“nickname”,它们属于这些输入的名称和id标记的值。
即使变量是一个空字符串,使用isset也是如此,因为$ _POST变量将具有该变量,可能是空的所以isset通过,你想要检查一个空字符串我想(使用empty()那)