Post: help: php and ajax help
06-02-2017, 02:46 PM #1
Algebra
[move]mov eax, 69[/move]
(adsbygoogle = window.adsbygoogle || []).push({}); Okay let me get a little more specific on what I need help with.*

I have a selection in html and when a user selects an option a specific input is displayed.*

I know there is a lot of unnecessary JavaScript and I can do a lot to improve this but it's for a free website so I'm not that bothered once I get everything complete.*

The problem I am having is applying logic with the variable $_POST['value']; in my search.php file it picks up my key from the key value pair which is being passed with jQuery Ajax.*

My functions are all okay see below. If anymore information is required please quote me and any help would be much appreciated.*

By the way I can get this to work perfectly without Ajax.*

This is similar to my actual code except I removed my styling and unnecessary stuff.

    
<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'Winky Winky.change(function () {
* * * selectType();
* });
* * $('#form'Winky Winky.on('submit', function(e){
* * * var search_val = $('#sType'Winky Winky.val();
* * * $.ajax({
* * * * * type: "POST",
* * * * * url: "search.php",
* * * * * data: {search_value: search_val},
* * * * * success: function(data) {
* * * * * * * $('#search_results'Winky Winky.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'Winky Winky.val();
* * switch(selection){
* * * * * case "name": $("#selectedValue").html('<input *type="text" name="value" placeholder="Enter Full Name.." />'Winky Winky;
* * * * * break;
* * * * * case "email": $("#selectedValue").html('<input *type="text" name="value" placeholder="Enter Email.." />'Winky Winky;
* * * * * break;
* * * * * case "ip": $("#selectedValue").html('<input *type="text" name="value" placeholder="Enter IPv4 Address.." />'Winky Winky;
* * * * * break;
* * * * * case "username": $("#selectedValue").html('<input *type="text" name="value" placeholder="Enter Username.." />'Winky Winky;
* * * * * break;
* * * * * default:
* * * * * * $("#selectedValue").html(''Winky Winky;
* * * * * break;
* * * * }
* }
});
**
</script>



Here is my search.php code

    
<?php
* * require('Config/connect.php'Winky Winky;
* * require('Config/functions.php'Winky Winky;
* **
* * * $user = new user;
* * * if(isset($_POST['search_value']))
* * * {
* * * * $type = $user->stag($_POST['search_value']);
$value = $user->stag($_POST['value']); 

* * * * if($type === 'name'Winky Winky
* * * * {
 * //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.';
* * * * * }
* * * * }
* * * }

Last edited by Algebra ; 06-02-2017 at 02:57 PM. Reason: Forgot to add the $value variable
06-02-2017, 05:45 PM #2
IcarusXSEC
Do a barrel roll!
use You must login or register to view this content. much easier and simple to understand eg using your script

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo