Support » Developing with WordPress » Adding ShortCode twice on the page does not work

  • I created a custom plugin for ajax call
    The problem when I add the shortcode twice(two instance) on the page; One of them will not work

    I tried to make static id for each element or unique identifier but it does not work

    I tried also to wrap the functions on PHP/JS with a class and call action functions with instance of that class but it does not work either

    I am using “Elementor” if that is related.

    Note : I am newbie to WordPress and PHP

    This is a sample of my code in the custom plugin : PHP file which is ts.php

    <?php
    /*
    Plugin Name: TS 
    description: A custom plugin to call and handle AJAX request 
    Version: 1.0.0
    Author: y.w.
    */
    
    function ts()
    {
        /* creating string variable to hold the content */
        
        $content=''; /* create a string */
        $content .='<div id="div_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 .='<div id="div_msg" ><mark id="m_msg"></mark></div>';
        
        $content .='</div>';
        
        return $content;
    }
    add_shortcode('tsform','ts');
    
    /* Include CSS and Script */
    add_action('wp_enqueue_scripts','plugin_css_jsscripts');
    function plugin_css_jsscripts() 
    {
    
       // JavaScript
       wp_enqueue_script( 'script-js', plugins_url( '/ts.js', __FILE__ ),array('jquery'));
    
       // Pass ajax_url to script.js
       wp_localize_script( 'script-js', 'ts_object',
       array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
    }
    
    /* AJAX request */
    
    ## Search record
    add_action( 'wp_ajax_searchTSList', 'searchTSList_callback' );
    add_action( 'wp_ajax_nopriv_searchTSList', 'searchTSList_callback' );
    
    function searchTSList_callback() {
        
        $return = [];
        $msg='';
        $ts=array();
    
            if( isset($_POST['tsSubmit']) && $_POST['tsSubmit']=='1')// data submission success
        {
    
         /*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-load.php';
        include_once $path . '/pioneer/wp-config.php';
        
     
    
        $db = new mysqli(DB_HOST, DB_USER,DB_PASSWORD, DB_NAME); //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) { 
        $en_data = array();
        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;
        }   
        }else // data submission error
        {
        $msg='**Your data was not submitted ! ';
        $return['success']=0;
        $return['message']=$msg;
        }
    
        echo json_encode($return,JSON_FORCE_OBJECT);
        wp_die();  
        
    }

    and this is the Script File : ts.js

    jQuery(document).ready(function($){
    
      // AJAX url
      var ajax_url = ts_object.ajax_url;
    
      
      // Search record
      $('#btn_submit').click(function(){
        
        
        var ID = $("#txt_ID").val();
        
        
        if ( !validateID(ID))
        {
            return false; //exit process inputs
            
        }
        
        
        // Fetch filtered records (AJAX with parameter)
        var data = {
          'tsSubmit':'1',
              'action': 'searchTSList',
          'ID': ID
        };
    
        $.ajax({
          url: ajax_url,
          type: 'post',
          data: data,  
          success: function(data){
        
            // Add new rows to table
           createmsg(data)
           
          }
        });
      });
      
      // validate ID
    function validateID(ID)
    {
        //blank or empty or null or whitespace
        if(!$.trim(ID))
        {
            
            $("#div_msg").css('display','block'); 
            $("#m_msg").text('**You must enter your ID !');
            return false;   
        }
        
        //not digit
        if(/\D/g.test(ID ))
        {
            
            $("#div_msg").css('display','block');
            $("#m_msg").text('**You must enter digit ID !');
            return false;
        }
    
        //not valid len
        var validLen= 10;
        if(ID.length != validLen)
        {
            
            $("#div_msg").css('display','block');
            $("#m_msg").text('**You must valid length ID !');
            return false;
            
        }
        
        return true;    
    }
      // 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);
            
        }
      }
    });
Viewing 11 replies - 1 through 11 (of 11 total)
  • Joy

    (@joyously)

    Just looking at the code you showed, there are a few things:
    1) Id attributes must be unique in a page. Your shortcode can have parameters, which you can use to make the output unique.
    2) Submit buttons should be in a <form> element, which then limits their scope.
    3) Each AJAX submission should have the action hidden input instead of adding it in JS.
    4) The AJAX callback is already in WP context, and does not need to load WP or handle the database connection.
    5) The AJAX callback should be checking a nonce and user capability before accessing the data. (especially for writing to the database)
    6) The JS should work off of a class selector instead of ID selector, so that it can handle more than one. I suggest a class on the <form> tag.
    7) The JS should use $.post instead of $.ajax for best results.

    3) 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 ?

    Joy

    (@joyously)

    You should try using the Developer Tools in your browser to see what is happening. The Network tab will show the AJAX request and response. The Console will show the errors. You can also use the PHP error_log() function to dump the variables in the PHP function to verify them.
    I can’t debug code at a distance, especially code I haven’t seen.

    The reason you should put the action input in the PHP and not the JS, and to use a form tag, is so that it can still work without Javascript.

    Thanks 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 1 week, 5 days ago by mubaraba. Reason: code fix
    Joy

    (@joyously)

    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.

    Thanks 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 1 week, 3 days ago by mubaraba.
    Joy

    (@joyously)

    Your code has ID attributes all over it!

        $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" />';

    You did add a class on the <form> tag, but everything else has id=. Remove all of those ID attributes because you want to be able to use the shortcode multiple times on a page. Put classes instead, but only if needed by the JS or styling. Then you have to modify your JS to use the classes instead of the IDs.

    Thanks 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;

    Joy

    (@joyously)

    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).

    The nonce should be part of the form, and use something specific to that transaction. A good example is using the post ID, if the action is to delete the post. You would want to use the nonce to verify that the nonce matches, so the wrong post isn’t deleted. 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. But you can use this function https://developer.wordpress.org/reference/functions/wp_nonce_field/

    Your 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.

    mubaraba

    (@mubaraba)

    Thanks 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 world

    Your 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 ?

    mubaraba

    (@mubaraba)

    Hi 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 1 week ago by mubaraba.
Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.