1

I am a newbie to wordpress ... please help ... cannot get this code to work ... the [datatable} shortcode is a plugin shortcode (so it does exist)

Worpress page:

<label>Client ID Nr</label>   <input id="clientidnr" name="clientidnr" placeholder="9999" type="text">   <input type="button" style="background-color:#6D4053;color:white;" onclick="customidnr(0, 'shortc')" name="submit" value="Submit" />

CUSTOMIZED JS:

function customidnr(idnr) {
  var input;
  if (idnr !== undefined && idnr !== 0) {
    input = idnr;
    storeDataidnr(input);
    // alert("Storing idnr data1: " + input);
  } else {
    input = document.getElementById("clientidnr").value;
    storeDataidnr(input);
    // alert("Storing idnr data2: " + input);
  }

   jQuery.post(
    ajaxurl, 
    {
        'action': 'custom_id_nr',
        'idnr': input
    }, 
    function(response){
        alert('The server responded: ' + response);
    }
);

}

function storeDataidnr(clientidnr) {
  alert("ML/TF Risk data will be displayed for ID Nr:  " + clientidnr);
  sessionStorage.setItem("idnr", clientidnr);
}

FUNCTIONS.PHP

/** jquery fix  ********************************************************************************************** */
add_action( 'wp_enqueue_scripts', 'load_old_jquery_fix', 10 );

function load_old_jquery_fix() {
    if ( ! is_admin() ) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', ( "//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" ), false, '1.11.3' );
        wp_enqueue_script( 'jquery' );
    }
}


/** idnr **************************************************************************************************** */
add_action( 'wp_ajax_custom_id_nr', 'custom_id_nr' );
add_action( 'wp_ajax_nopriv_custom_id_nr', 'custom_id_nr' );

function custom_id_nr() {
    $clidnr = intval( $_POST['idnr'] );
    $shortcode = sprintf(
    '[wpdatatable id=30 var1="%1$s"]',
    $clidnr
    );
echo do_shortcode( $shortcode );
wp_die();
}
  • the wordpress page: <label>Client ID Nr</label> <input id="clientidnr" name="clientidnr" placeholder="9999" type="text"> <input type="button" style="background-color:#6D4053;color:white;" onclick="customidnr(0, 'shortc')" name="submit" value="Submit" /> – Danie Feb 7 at 7:07
0

I think your "do_shortcode" is not parsing the variable.

Try with this code:

echo do_shortcode('[datatable id=30 var1="'.$idnr.'"]');

* Note the ' before and after the .

  • thank you @Klian .... made the change ... still no result .. – Danie Feb 7 at 8:59
  • Could you elaborate more this?: "cannot get this code to work" Do you receive any error ? – Klian Feb 8 at 7:27
  • HI Klian .. no output no error code ... – Danie Feb 8 at 7:35
  • Klian ... I have updated the code in my original message above ... the result is now that "response" is showing the code of the table instead of the result of the code ... – Danie Feb 8 at 7:45
  • Thank you @Antti ... running the displays the right clientidnr and then the response shows what looks like the table code ... then no result and no error... – Danie Feb 8 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.