I made a search box in php and it works fine ... but when i implement it in wordpress it does not works correctly. I think the ajax is not working fine in wordpress.
I want to implement at it on cart page and want to get results also on same page.
//here is my form
<script>
$(document).ready(function()
{
$('#form').submit(function() {
$.ajax({
data: $(this).serialize(),
type: $(this).attr('method'),
url: $(this).attr('action'),
success: function(response) {
$('#result').html(response);
}
});
return false;
});
});
</script>
<body>
<form method="post" id="form" action="search.php">
<input type="text" name="record" id="record" placeholder="Enter Zip Code" onkeypress="return isNumberKey(event)">
<input type="submit" class="submit" value="find">
</form>
<div id="result" style="height:50px;width:200px;"></div>
<SCRIPT language=Javascript>
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode != 46 && charCode > 31
&& (charCode < 48 || charCode > 57))
return false;
return true;
}
</SCRIPT>
//and here is my action file
$file = 'PINCODES DELHIVERY.csv';
if ($_POST) {
$searchfor = $_POST['record'];
if (!empty($searchfor)) {
if(strlen($searchfor)==6) {
header('Content-Type: text/plain');
$contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*$pattern.*\$/m";
if(preg_match_all($pattern, $contents, $matches)){
echo "YES";
}
else{
echo "NO";
}
} else {
echo "Enter valid zip code";
}
} else {
echo "Enter Zip Code First";
}
}
can anyone help me. Thanks in Advance :)