Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter Banshee01

    (@banshee01)

    Please Anwser me 🙁

    Thread Starter Banshee01

    (@banshee01)

    Any Solution? Please

    Thread Starter Banshee01

    (@banshee01)

    UP

    Thread Starter Banshee01

    (@banshee01)

    hi there
    here is my js and php codes
    java:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script>
    
            <script>
            $('form').submit(function (e) { 
    
                e.preventDefault(); 
    
                var gnameInput = this.children["gname"].value; // the "gname" input 
    
                var postVariables = {
                    gname: gnameInput
                }; 
    
                var postUrl = this.action; // the "action" attribute of your form. 
    
                $.post(postUrl, postVariables, function (result) { 
    
                    $("#MyResultsDiv").html(result); 
    
                }).fail(function (result) {
                    console.log("Wean Error!");
                });
            });
            </script>

    and PHP:

    <?php
    // define variables and set to empty values
    $gname =  "";
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
       $gname = test_input($_POST["gname"]);
    }
    function test_input($data) {
       $data = trim($data);
       $data = stripslashes($data);
       $data = htmlspecialchars($data);
       return $data;
    }
    $urls= ("http://thegamesdb.net/api/GetGamesList.php?name=".$gname."");
    $search = new SimpleXMLElement(file_get_contents($urls));
    
    // HERE IS WHERE YOUR RESULTS ARE OUTPUT
    // THIS GETS SENT TO THE JavaScript CODE
    
    foreach($search as $object){
    echo "<li>".$object->GameTitle."     ";
    echo "     ID:".$object->id."</li>";
    }
    ?>

    my js and php is working fine i just dont know how to use it in function.php

    Thread Starter Banshee01

    (@banshee01)

    my code :

    function my_template_jquery() {
    wp_enqueue_script( '/js/games.js' );
    }
    add_action( 'wp_enqueue_scripts', 'my_template_jquery' );
    
    //////////////////////////////////////////////////////////////////
    // Register games Metabox
    //////////////////////////////////////////////////////////////////
    $prefixg = 'games_';
    
    $game_box = array(
        'id' => 'game-meta-box',
        'title' => 'gamesprofile',
        'page' => 'post',
        'context' => 'normal',
        'priority' => 'high',
        'fields' => array(
    		   array(
                'name' => 'GameName',
                'desc' => 'add game name here',
                'id' => $prefixg  . 'gname',
                'type' => 'form',
                'std' => ''
            ),
    				   array(
                'name' => 'game lists',
                'desc' => '',
                'id' => $prefixg  . 'glist',
                'type' => 'echogame',
                'std' => ''
            ),
    		    array(
                'name' => 'add your game ID here',
                'desc' => 'add gameID',
                'id' => $prefixg  . 'gameid',
                'type' => 'text',
                'std' => ''
            ),
    		 array(
                'name' => 'platforms',
                'desc' => 'chose your platforms',
                'id' => $prefixg  . 'platforms',
                'type' => 'text',
                'std' => ''
            )
        )
    );
    
    add_action('admin_menu', 'game_add_box');
    // Add meta box
    function game_add_box() {
        global $game_box;
       add_meta_box($game_box['id'], $game_box['title'], 'game_show_box', $game_box['page'], $game_box['context'], $game_box['priority']);
    }
    // Callback function to show fields in meta box
    function game_show_box() {
        global $game_box, $post;
        // Use nonce for verification
        echo '<input type="hidden" name="game_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
        echo '<table class="form-table">';
        foreach ($game_box['fields'] as $field) {
            // get current post meta data
            $gmeta = get_post_meta($post->ID, $field['id'], true);
            echo '<tr>',
                    '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
                    '<td>';
            switch ($field['type']) {
                case 'text':
                    echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $gmeta ? $gmeta : $field['std'], '" size="30" style="width:97%" />', '<br />', $field['desc'];
                    break;
                case 'form':
    			// define variables and set to empty values
                    echo '<form method="post" autocomplete="on" action="("admin/process_form.php");">
    				<input type="text" name="gname" >
    				<input type="submit"name="submit" value="search">', $gmeta ? $gmeta : $field['std'], '</form>', '<br />', $field['desc'];
                    break;
    
    			case 'echogame':
    	        echo '<div id="MyResultsDiv"> ', $gmeta ? $gmeta : $field['std'], '</div>', '<br />', $field['desc'];
    		    break;
            }
            echo     '</td><td>',
                '</td></tr>';
        }
        echo '</table>';
    }

    all work fines i just want know where is my problem to resulte game names under the search game i just need call my JS for show results

    Thread Starter Banshee01

    (@banshee01)

    see i want show result serch with java script under search bar so how can i made it? its possibel?

    Thread Starter Banshee01

    (@banshee01)

    like this?

    echo '<form method="post" autocomplete="on" action="("admin/process_form.php");">
    				<input type="text" name="gname" >
    				<input type="submit"name="submit" value="search">', $gmeta ? $gmeta : $field['std'], '</form>', '<br />', $field['desc'];
                    break;
    
    			case 'echogame':
    	        echo '<div id="MyResultsDiv"> ', $gmeta ? $gmeta : $field['std'], '</div>', '<br />', $field['desc'];
    		    break;

    and js:

    function my_template_jquery() {
    wp_enqueue_script( '/js/games.js' );
    }
    add_action( 'wp_enqueue_scripts', 'my_template_jquery' );

    so i made like this but not work can you just see my code and help me to find problems

    Thread Starter Banshee01

    (@banshee01)

    i know can you help me for js? how can i use js in function?

    Thread Starter Banshee01

    (@banshee01)

    so much thanks for not helping…

    Thread Starter Banshee01

    (@banshee01)

    Tim Nash ty for anwser but its not work 🙁

Viewing 10 replies - 1 through 10 (of 10 total)