Вы можете перенаправить в PHP
Сначала форма:
<form action="somefile.php">
<input type="text" id="search" name="search" value="" placeholder="Enter here..." />
<button>Search</button>
</form>
Второе:
// somefile.php
if (isset($_GET['search'])){
$search=$_GET['search'];
if(count($badwords)){
foreach($badwords as $theword)
$search = ereg_replace($theword,"haha",$search);
}
$search=preg_replace("/\s+/"," ",$search);
$keyword = str_replace(" ", "+", $search);
} else {
$keyword = str_replace(" ", "+a", $keyword);
}
// here you can do any checks with the search and redirect to anywhere
if (strlen($keyword)){
header("location: /file_{$keyword}.html");
}
Или вы можете использовать ajax для проверки и очистки ключевого слова:
<script type="text/javascript">
$(document).ready(function() {
$('.search-form').submit(function() {
$.ajax({ type: "POST", dataType: "HTML",
url: "clean.php",
data: { search: $('.search-form input:text').val()},
success: function(response){
if (response.length > 0) {
window.location.href = "/" + response;
}
}
});
</script>
Clean.php:
if (isset($_GET['search'])){
$search=$_GET['search'];
if(count($badwords)){
foreach($badwords as $theword)
$search = ereg_replace($theword,"haha",$search);
}
$search=preg_replace("/\s+/"," ",$search);
$keyword = str_replace(" ", "+", $search);
} else {
$keyword = str_replace(" ", "+a", $keyword);
}
// here you can do any checks with the search and redirect to anywhere
if (strlen($keyword)){
echo("file_{$keyword}.html");
} ?>
Дополнительную информацию о ajax / post / get (jQuery) можно найти в:
http://api.jquery.com/jquery.ajax/
http://api.jquery.com/jquery.post/
http://api.jquery.com/jquery.get/