samedi 11 avril 2015

Jquery form submit losing form data

I have this form which is supposed to send the info to the database for a username search. I'm putting together a search function for private servers in our student dormitory. We have a dude with username <lol> and it seems we can't search him. Other usernames search just fine. I'm I missing something?


This is the form.php file:



<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery.validation/1.13.1/jquery.validate.js"></script>
<script src="//cdn.jsdelivr.net/jquery.validation/1.13.1/jquery.validate.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery.validation/1.13.1/additional-methods.js"></script>
<script>

$(document).ready(function() {
$('#checkForm').validate({
rules: {
IpSearch: {
ipv4:true,
require_from_group: [1, ".required_group"]
},
UserName: {
minlength: 3,
require_from_group: [1, ".required_group"]
}
},
submitHandler: function(form) {
console.log( $("#checkForm").serialize());
$('#results').text( $("#checkForm").serialize());
$.post('file.php', $("#checkForm").serialize(), function(data) {
$('#checkResult').html(data);

});
}
});
});
</script>
</head>
<body>


<form role="form" id="checkForm" name="checkForm" method="post">
<div class="form-group">
<label>Internal IP:</label>
<input id="IpSearch" name="IpSearch" placeholder="Enter IP" class="form-control optional required_group" type="text">
</div>
<div class="form-group">
<label>Username</label>
<input id="UserName" name="UserName" value="<?php if(!empty ($_POST) && isset($_POST['checkThis'])){echo $_POST['checkThis']; } else{}?>" placeholder="admin" class="form-control optional defaultInvalid required_group" type="text">
</div>
<button id="search" name="search" value="doSearch" class="btn btn-info">Search</button>
</form>


<div id="results"></div>
<div id="checkResult"></div>

</body>
</html>


and this is the file.php beginning:



<?php
echo "<pre>";
var_dump($_POST);
echo "</pre>";
// .... continues but irrelevant since I'm not getting any post data


On clicking the button, I get this in browser console:



"IpSearch=&UserName=%3Clol%3E&search=doSearch"


on #results I get: IpSearch=&UserName=%3Clol%3E&search=doSearch


on #checkResult I get:



array(3) {
["IpSearch"]=>
string(0) ""
["UserName"]=>
string(5) ""
["search"]=>
string(8) "doSearch"


}


Aucun commentaire:

Enregistrer un commentaire