<form id="form" method="post">
* <select name="sType" id="sType"><!-- Search Type -->
* * <option value="name" selected="selected">Full Name Search</option>
* * <option value="email">Email Search</option>
* * <option value="ip">IPv4 Search</option>
* * <option value="username">Username Search</option>
* </select>
* <div id="selectedValue"></div>
* * <input type="submit" name="submit" value="Search Now" />
</form>
<div id="search_results"></div>
<script type="text/javascript">
$(document).ready(function () {
**
* selectType();
* $('#sType'.change(function () {
* * * selectType();
* });
* * $('#form'.on('submit', function(e){
* * * var search_val = $('#sType'.val();
* * * $.ajax({
* * * * * type: "POST",
* * * * * url: "search.php",
* * * * * data: {search_value: search_val},
* * * * * success: function(data) {
* * * * * * * $('#search_results'.html(data);
* * * * * }
* * * });
* * * *e.preventDefault();
* * * *
* * });
//Function to display the input we want and I know I could have set 1 input field.
* function selectType()
* {
* * var selection = $('#sType'.val();
* * switch(selection){
* * * * * case "name": $("#selectedValue").html('<input *type="text" name="value" placeholder="Enter Full Name.." />';
* * * * * break;
* * * * * case "email": $("#selectedValue").html('<input *type="text" name="value" placeholder="Enter Email.." />';
* * * * * break;
* * * * * case "ip": $("#selectedValue").html('<input *type="text" name="value" placeholder="Enter IPv4 Address.." />';
* * * * * break;
* * * * * case "username": $("#selectedValue").html('<input *type="text" name="value" placeholder="Enter Username.." />';
* * * * * break;
* * * * * default:
* * * * * * $("#selectedValue").html('';
* * * * * break;
* * * * }
* }
});
**
</script>
<?php
* * require('Config/connect.php';
* * require('Config/functions.php';
* **
* * * $user = new user;
* * * if(isset($_POST['search_value']))
* * * {
* * * * $type = $user->stag($_POST['search_value']);
$value = $user->stag($_POST['value']);
* * * * if($type === 'name'
* * * * {
* //Could have used filter_var($value, FILTER_SANITIZE_STRING) but this does perfect lol as I only want a-z
* * * * * if (preg_match('/^[a-z ]+$/i', $value) == true) {
* * * * * * * $user->name_search($pdo);
* * * * * }else {
* * * * * * * echo 'Invalid Name please use only words and non special characters.';
* * * * * }
* * * * }
* * * }
Copyright © 2024, NextGenUpdate.
All Rights Reserved.