How to use shortcode on a custom page in a theme? Let say I have a page that has a jQuery ajax function. I am able to send the data via jquery post on my_form.php page. On confirm.php page, I want to use a shortcode from Contact Form DB plugin. Below are the codes that I made,

my_form.php

<?php
get_header(); 
// Include all the theme functions    
?>

<form name="season-form" class="form-horizontal" method="post" action="">
  <div class="form-group form-group-lg">
    <label for="carNo" id="label-cust"> Vehicle Registration No</label>
    <input type="text" class="form-control" name="vehicle_no" id="vehicle_no" placeholder="BHK1991">
  </div>
  <div class="form-group form-group-lg">
    <label for="email" id="email">Email</label>
    <input type="email" class="form-control" name="email" id="email" placeholder="myMail@example.com">
  </div>
  <button type="submit" class="btn btn-primary" id="submit_payment">Make Payment</button>
</form>
<div id="result"></div>

<?php get_footer(); ?>

my_function.js

jQuery(document).ready(function($) {
    $('#submit_payment').click(function(e){
        e.preventDefault();
        var str = $("form[name=season-form]").serialize();
        //alert(str);
        $.ajax({
            type: "POST",
            url: url_to_confitm.php,
            data: str 
        }).done(function(data){
            $("#result").html(data);
        });
    });
});

confirm.php

if(isset($_POST['vehicle_no'])){
    $vehicle_no = $_POST['vehicle_no'];
    $email = $_POST['email'];

    echo "Your Data: <br>$vehicle_no <br>$email<p />";
}

echo do_shortcode('[cfdb-table form="season parking form_copy"]');
  1. I am able to get the result of post data but the shortcode appears to be nothing.
  2. If I use the shortcode on my_form.php page, it display the data perfectly.

Read more here: Use Shortcode on Custom Page


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: