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/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();
}
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/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();
}
Share
Improve this question
edited Feb 8, 2020 at 13:40
Antti Koskinen
6,0438 gold badges15 silver badges26 bronze badges
asked Feb 7, 2020 at 7:05
DanieDanie
112 bronze badges
1
- 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 Commented Feb 7, 2020 at 7:07
1 Answer
Reset to default 0I 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 .
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744766045a4592466.html
评论列表(0条)