我使用Tag Manager plugin为我的表单创建标签,并使用jquery中的serialize()函数将值传递给php。当我检索值时,我得到一个空字符串但没有serialize()函数,标签创建者工作正常。
<input type="text" name="tags" placeholder="Tags" class="tm-input form-control tm-input-info" id="collaborationsSoughtInput" name="collaborationsSoughtInput" />
这是我的jquery函数
function adduser() {
$.post("functions/add-user.php", $("#registerForm").serialize()).done(function(data) {
var result = $.trim(data);
if (result == "OK") {
window.location.href = "login";
} else {
console.log("Register error :" + result);
}
});
}
和php代码
$collaborationsSoughtInput = $con->real_escape_string($_POST['hidden-tags']);
这是工作example
这里有完整的表格
<form action="" id="registerForm" class="mb-4" style="margin-bottom: 50px" method="post" enctype="multipart/form-data">
<div class="form-group has-feedback row">
<label for="fullnameInput" class="col-sm-3 col-form-label" required>Full Name *</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="fullname" name="fullname" required>
</div>
<span id="fullNameError" class="color-red hide-me">Full Name Error</span>
</div>
<div class="form-group has-feedback row">
<label for="usernameInput" class="col-sm-3 col-form-label">Username *</label>
<div class="col-sm-8">
<input minlength="4" type="text" class="form-control" id="username" name="username">
</div>
<span id="usernameError" class="color-red hide-me">Userame Error</span>
</div>
<div class="form-group has-feedback row">
<label for="passwordInput" class="col-sm-3 col-form-label" required>Password *</label>
<div class="col-sm-8">
<input class="form-control" type="password" value="hunter2" id="password" name="password">
</div>
<span id="passwordError" class="color-red hide-me">Password Error</span>
</div>
<div class="form-group has-feedback row">
<label class="col-sm-3 col-form-label" for="collaborationsSoughtInput">Collaborations Sought *</label><br/>
<div class="col-sm-8">
<input type="text" name="tags" placeholder="Tags" class="tm-input form-control tm-input-info" id="collaborationsSoughtInput" name="collaborationsSoughtInput" />
</div>
<span id="collaborationsError" class="color-red hide-me">Collaborations Error</span>
</div>
</form>
在控制台中,我得到了这个
<b>Notice</b>: Undefined index: hidden-tags in ...
答案 0 :(得分:0)
.serialize()的整个输出是空的?似乎你的表单选择器可能是错误的。