I want implement OTP SMS mobile verification in Wordpress
I want when send SMS to user, change view to another form and get user SMS
My problem is when run ajax code it send SMS, but dosnt work require_once to include another view and get error in browser console /wp-admin/admin-ajax.php 500 (Internal Server Error)

My HTML code

<form action="" method="post" id="first-form">
   <div class="form-row">
      <label for="user_mobile"></label>
      <input type="tel" name="user_mobile" id="mobile" >
   <div class="form-row">
      <input type="button" class="btnSubmit" value="send OTTP" onClick="sendOTP();">

My Ajax code

function sendOTP() {
    var ajaxurl = '<?php echo admin_url("admin-ajax.php"); ?>';
    var number = jQuery("#mobile").val();
    var data = {
       "mobile_number": number,
       "action": "send_otp"
    jQuery.post(ajaxurl, data, function (response) {

My PHP code

add_action('wp_ajax_send_otp', 'send_otp');
add_action('wp_ajax_nopriv_send_otp', 'send_otp');

function send_otp()
    switch ($_POST["action"]) {

       case "send_otp":
       require_once (get_template_directory_uri() . '/page-templates/template-submit-otp.php');

  • Your switch statement is not closed, and you could just use load_template() to load the template file. – Sally CJ Feb 16 at 9:00

Your Answer

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

Browse other questions tagged or ask your own question.