• Here’s the situation :

    I would like, either with querystrings or with another way, to populate a Ninja Forms form with values from a MySQL query to a database table.

    Here is how it works for now :

    <?php
    /**
    * Template Name: Key Editor
    *
    * The template for displaying the Key Editor
    *
    * @package QSI
    */
    
    get_header();
    ?>
    <?php  
    
    $fetchKEY = '12345'; 
    
    global $wpdb;
    $results = $wpdb->get_results("SELECT keylic, keycie from pos_keys where keylic = '12345'", OBJECT);
    $result=mysql_query($results);
    ?>
    <div class="container">
    <form name="form" method="GET" action="../cle-best">
      Keyfield <input type="text" maxlength="10" name="keyinput" value="<?php echo $fetchKEY ?>">
    <input type="hidden" maxlength="40" name="cie" value="<?php echo $result["keylic"] ?>">
    <input type="submit" value="submit" id="submit"/>
    </form>
    </br>
    </br>
    <?php
    get_footer();
    ?>

    Now the problem is that my link will only display link.php?keyinput=12345&cie=

    So now it gives a problem to my functions.php script which is :

    function my_filter_function( $data, $field_id ){
    
      if( $field_id == 12 ){
        $data['default_value'] = $_GET['keyinput'];
      }
      if( $field_id == 18 ){
        $data['default_value'] = $_GET['cie'];
      }
      if( $field_id == 10 ){
        $data['default_value'] = '1';
      }
      return $data;
    }
    add_filter( 'ninja_forms_field', 'my_filter_function', 10, 2 );

    Do you have any solution? Or even, if possible, a way to populate the form with a query without having to manage querystrings?

    Thank you!

  • The topic ‘Populate Querystrings from MySQL query in WordPress’ is closed to new replies.