mubaraba
Forum Replies Created
-
My default language for the WordPress website is the English language
I am using English and Arabic for building the website
Should I modify the function [is_rtl]Thanks for replay
- This reply was modified 5 years, 4 months ago by mubaraba.
Please see my result on this link :
as you see the labels is not on ltr direction
also the checkbox and forget passwordand after login window
and profile
https://ibb.co/R44hjdtI think the whole plugin is missed up after translation
Forum: Developing with WordPress
In reply to: Adding ShortCode twice on the page does not workHi Joy again ! This is my update …
The nonce should be part of the form
I was able to do that using the link you provide as follwing code :
php file :
<?php /* Plugin Name: TS description: A custom plugin to call and handle AJAX request Version: 1.0.0 Author: y.w. */ class TS { function ts() { /* getting shortcode parameter */ $data = shortcode_atts(array('id' => ''), $atts) ; /* creating string variable to hold the content */ $content=''; /* create a string */ $content .='<div id="div_ts_form">'; $content .='<form class="ts_form">'; $content .='<input type="hidden" class="_wpnonce" name="_wpnonce" value="' . wp_create_nonce( 'send_form' ) . '" />'; $content .='<div id="div_ID">'; $content .='<input id="txt_ID" type="text" placeholder="your ID" />'; $content .='</div>'; $content .='<div id="div_btn">'; $content .='<input id="btn_submit" type="submit" name="btn_submit" value="Show Info" />'; $content .='</div>'; $content .='</form>'; $content .='<div id="div_msg" ><mark id="m_msg"></mark></div>'; $content .='</div>'; // Enqueue JavaScript File wp_enqueue_script( 'script-js', plugins_url( '/ts.js', __FILE__ ),array('jquery')); // Pass parameters to script file wp_localize_script( 'script-js', 'ts_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' )) ); return $content; } function searchTSList_callback() { $return = []; $msg=''; $ts=array(); if( isset($_POST['tsSubmit']) && $_POST['tsSubmit']=='1')// data submission success { // Check for nonce security $nonce = $_POST['nonce']; if ( ! <strong>wp_verify_nonce</strong>( $nonce, 'send_form' ) ) { $msg='Can not view data for security reason ! '; } //pass security check else { /*get information form the post submit */ $ID=($_POST['ID'] ?? ''); //get the result if( $ID != '') { $msg .= ' your id is submitted which is ' . $ID; //record the number of records found } else { $msg.='** Nothing was submitted!'; } /* return info for the user */ $return['success']=1; $return['message']=$msg; } } // data submission error else { $msg='**Your data was not submitted ! '; $return['success']=0; $return['message']=$msg; } echo json_encode($return,JSON_FORCE_OBJECT); wp_die(); } } // creating object from the class $object = new TS(); /* adding shortcode */ add_shortcode('tsform',array($object ,'ts')); /* AJAX request */ add_action( 'wp_ajax_send_form', array($object ,'searchTSList_callback') ); add_action( 'wp_ajax_nopriv_send_form', array($object , 'searchTSList_callback') );and JavaScript file :
jQuery(document).ready(function($){ // AJAX url var ajax_url = ts_object.ajax_url; //submit form $('.ts_form').submit(function(e) { //prevent form from reload e.preventDefault(); var ID = $("#txt_ID").val(); var nonce = $("._wpnonce").val(); // Fetch filtered records (AJAX with parameter) var data = { 'tsSubmit':'1', 'ID': ID, 'action': 'send_form', 'nonce' : nonce }; // post data $.post(ajax_url,data, function(response){ // Add new rows to table createTableRows(response,lang); }); }); // Add response object function createmsg(data) { var jdata = JSON.parse(data); if( jdata.success == 1) //submission sucess { $("#m_msg").text(jdata.message); $("#div_msg").css('display','block'); }else //submission failed { var mess =''; mess = '**Your information has not been submitted! '; $("#div_msg").css('display','block'); $("#m_msg").text(mess); } } });as you see on the sample code ; I add the nonce on hidden field and pass it to backend to be verified and it is work fine .
but this is too generic.
what should I use in my case ? instead of class to get the value of the element ..
.
.
.
After adding the nonce ; the second instance is working fine but it works using the input from the first instance and producing the output ( message) for the both instance.I think the problem is now related to elements access.
Thanks;
- This reply was modified 5 years, 5 months ago by mubaraba.
Forum: Developing with WordPress
In reply to: Adding ShortCode twice on the page does not workThanks for your replay Joy !
I think you put different code here, because there is an extra brace in your PHP, and it refers to a variable that isn’t defined ($db).
Sorry; I was not omitted by mistake
I don’t understand what you are doing, or why you want more than one on a page, so I don’t know what to tell you to use.
I am using the shortcode to add two instances for transaction search by ID. When the user enter the ID and press the button a table from the database will be shown.
One instance : will be used on desktop website by a button on menu item.
Second instance : will be used on mobile/tablet website which is hidden desktop by a button on menu item (hamburger menu)how to use : when the user click (a button) on menu item whether on mobile or desktop website; The shortcode will appear on popup window
Note : I have two different nav menus on the website cause each one has different content.
The nonce should be part of the form, and use something specific to that transaction. A good example is using the post ID
I have no idea how to use nonce a part of the form cause I did not able to use hidden action element yet !
So, how to use/reach to post ID and create nonce as part of the form ? could you give an example ?
I am newbie to WordPress worldYour JS is now using the class $(“.txt_ID”), but this is too generic. It should be the one that goes with the submit button that was clicked.
What do you mean ? I change it to classes without IDs as you suggest …. what should I do exactly to access the element ?
Forum: Developing with WordPress
In reply to: Adding ShortCode twice on the page does not workThanks Joy for your replay!
I did what you say but as I mention when I press the button on first instance the result will be produced for the first instance and second one ( even that the textbox is empty on the second instance). Additionally; when I try to press the button on the second instance it does not response as the first one.I will put the sample code so , you can test it :
This is my PHP file :<?php /* Plugin Name: TS description: A custom plugin to call and handle AJAX request Version: 1.0.0 Author: y.w. */ class TS { function ts() { /* getting shortcode parameter */ $data = shortcode_atts(array('id' => ''), $atts) ; /* creating string variable to hold the content */ $content=''; /* create a string */ $content .='<div class="div_ts_form">'; $content .='<form class="ts_form">'; $content .='<div class="div_ID">'; $content .='<input class="txt_ID" type="text" placeholder="your ID" />'; $content .='</div>'; $content .='<div class="div_btn">'; $content .='<input class="btn_submit" type="submit" name="btn_submit" value="Show Info" />'; $content .='</div>'; $content .='</form>'; $content .='<div class="div_msg" ><mark class="m_msg"></mark></div>'; $content .='</div>'; // Enqueue JavaScript File wp_enqueue_script( 'script-js', plugins_url( '/ts.js', __FILE__ ),array('jquery')); $nonce = wp_create_nonce('ajax-nonce');; // Pass parameters to script file wp_localize_script( 'script-js', 'ts_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ),'nonce' => $nonce) ); return $content; } function searchTSList_callback() { $return = []; $msg=''; $ts=array(); if( isset($_POST['tsSubmit']) && $_POST['tsSubmit']=='1')// data submission success { // Check for nonce security $nonce = $_POST['nonce']; if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) ) { $msg='Can not view data for security reason ! '; } //pass security check else { /*get information form the post submit */ $ID=($_POST['ID'] ?? ''); //get the result if( $ID != '') { $msg .= ' your id is submitted which is ' . $ID; //record the number of records found } else { $msg.='** Nothing was submitted!'; } //close connection to db $db->close(); /* return info for the user */ $return['success']=1; $return['message']=$msg; } } // data submission error } else { $msg='**Your data was not submitted ! '; $return['success']=0; $return['message']=$msg; } echo json_encode($return,JSON_FORCE_OBJECT); wp_die(); } } // creating object from the class $object = new TS(); /* adding shortcode */ add_shortcode('tsform',array($object ,'ts')); /* AJAX request */ add_action( 'wp_ajax_send_form', array($object ,'searchTSList_callback') ); add_action( 'wp_ajax_nopriv_send_form', array($object , 'searchTSList_callback') );and this is my JavaScript file :
jQuery(document).ready(function($){ // AJAX url var ajax_url = ts_object.ajax_url; // nonce security pharase var nonce = ts_object.nonce; //submit form $('.ts_form').submit(function(e) { //prevent form from reload e.preventDefault(); var ID = $(".txt_ID").val(); // Fetch filtered records (AJAX with parameter) var data = { 'tsSubmit':'1', 'ID': ID, 'action': 'send_form', 'nonce' : nonce }; // post data $.post(ajax_url,data, function(response){ // Add new rows to table createmsg(response); }); }); // Add response object function createmsg(data) { var jdata = JSON.parse(data); if( jdata.success == 1) //submission sucess { $(".m_msg").text(jdata.message); $(".div_msg").css('display','block'); }else //submission failed { var mess =''; mess = '**Your information has not been submitted! '; $(".div_msg").css('display','block'); $(".m_msg").text(mess); } } });Regards;
Forum: Developing with WordPress
In reply to: Adding ShortCode twice on the page does not workThanks for you replay !
That was my first point (IDs must be unique on a page). And number 6 is about using classes instead of IDs. Fix your shortcode handler function so it doesn’t output IDs, and then change your JS to use the class instead of the ID.
I did use the classes instead of IDs but the result was producing the same output message for all instance and second instance is not working either
1) Id attributes must be unique in a page. Your shortcode can have parameters, which you can use to make the output unique.
I do not know what do you mean exactly by id must be unique …
do you mean the attribute name for each instance must use a unique set or the parameters itself ( all of them ) must be unique on the page ..
could you write a sample using my code ?I appreciate your help.
- This reply was modified 5 years, 5 months ago by mubaraba.
Forum: Developing with WordPress
In reply to: Adding ShortCode twice on the page does not workThanks for your replay Joy !
I tried to trace the errors as you suggested by using developer tools …
It shows the following :
[DOM] Found 2 elements with non-unique id #btn_submit:…
[DOM] Found 2 elements with non-unique id #txt_ID…What is the best solution to overcome with this problem?
This is my current code Now :
PHP file :
<?php /* Plugin Name: TS description: A custom plugin to call and handle AJAX request Version: 1.0.0 Author: y.w. */ class TS { function ts() { /* getting shortcode parameter */ $data = shortcode_atts(array('id' => ''), $atts) ; /* creating string variable to hold the content */ $content=''; /* create a string */ $content .='<div id="div_ts_form">'; $content .='<form class="ts_form">'; $content .='<div id="div_ID">'; $content .='<input id="txt_ID" type="text" placeholder="your ID" />'; $content .='</div>'; $content .='<div id="div_btn">'; $content .='<input id="btn_submit" type="submit" name="btn_submit" value="Show Info" />'; $content .='</div>'; $content .='</form>'; $content .='<div id="div_msg" ><mark id="m_msg"></mark></div>'; $content .='</div>'; // Enqueue JavaScript File wp_enqueue_script( 'script-js', plugins_url( '/ts.js', __FILE__ ),array('jquery')); $nonce = wp_create_nonce('ajax-nonce');; // Pass parameters to script file wp_localize_script( 'script-js', 'ts_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ),'nonce' => $nonce) ); return $content; } function searchTSList_callback() { $return = []; $msg=''; $ts=array(); if( isset($_POST['tsSubmit']) && $_POST['tsSubmit']=='1')// data submission success { // Check for nonce security $nonce = $_POST['nonce']; if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) ) { $msg='Can not view data for security reason ! '; } //pass security check else { /*get information form the post submit */ $ID=($_POST['ID'] ?? ''); /* get data from database using CID or NID */ $path = $_SERVER['DOCUMENT_ROOT']; include_once $path . '/pioneer/wp-config.php'; $db = new Connection(); //connect to database // Test the connection: if (mysqli_connect_errno())// Connection Error { $msg=("**Couldn't connect to the database: ".mysqli_connect_error()); $return['success']=0; $return['message']=$msg; } else //connection success { //query the database $sql=''; $sql = "SELECT Full_Name,Type,Status,Note FROM Individual WHERE ID ='" . $ID ; } $result = $db->query($sql); //get the result $rowsNo=$result->num_rows; if ( $rowsNo > 0) { while($row = $result->fetch_assoc())// output data of each row { $ts[] = array( 'Name' => $row['Full_Name'],'Type' => $row['Type'], 'Status' =>$row['Status'], 'Note' => $row['Note']); } $msg .= $rowsNo . ' records are found.'; //record the number of records found } else { $msg.='**No records are found!'; } //close connection to db $db->close(); /* return info for the user */ $return['success']=1; $return['message']=$msg; $return['rows']= $ts; } } // data submission error } else { $msg='**Your data was not submitted ! '; $return['success']=0; $return['message']=$msg; } echo json_encode($return,JSON_FORCE_OBJECT); wp_die(); } } // creating object from the class $object = new TS(); /* adding shortcode */ add_shortcode('tsform',array($object ,'ts')); /* AJAX request */ add_action( 'wp_ajax_send_form', array($object ,'searchTSList_callback') ); add_action( 'wp_ajax_nopriv_send_form', array($object , 'searchTSList_callback') );and Script file :
jQuery(document).ready(function($){ // AJAX url var ajax_url = ts_object.ajax_url; // nonce security pharase var nonce = ts_object.nonce; //submit form $('.ts_form').submit(function(e) { //prevent form from reload e.preventDefault(); var ID = $("#txt_ID").val(); // Fetch filtered records (AJAX with parameter) var data = { 'tsSubmit':'1', 'ID': ID, 'action': 'send_form', 'nonce' : nonce }; // post data $.post(ajax_url,data, function(response){ // Add new rows to table createmsg(response); }); }); // Add response object function createmsg(data) { var jdata = JSON.parse(data); if( jdata.success == 1) //submission sucess { $("#m_msg").text(jdata.message); $("#div_msg").css('display','block'); }else //submission failed { var mess =''; mess = '**Your information has not been submitted! '; $("#div_msg").css('display','block'); $("#m_msg").text(mess); } } });- This reply was modified 5 years, 5 months ago by mubaraba. Reason: code fix
Forum: Developing with WordPress
In reply to: Adding ShortCode twice on the page does not work3) Each AJAX submission should have the action hidden input instead of adding it in JS.
Thanks for your replay !
I was able to do all your recommendations except the the hidden field ; I could not make work
However, when I apply what you mention, it does not work either for the second instance.
Do you have other suggestions ?