php - how to submit ajax form on same page in wordpress -


i'm new wordpress, want customize form, created form user can input data front end. when submit form, if successful, within <div id="feedback"></div>, whole page has been shown again. because of "data" in ajax success or error function. how can data in echo??

<?php /* template name: complain */ get_header(); ?>  <?php  if($_post['submit']) {     global $wpdb;      $complain_name = $_post['complain_name'];        if($wpdb->insert(             'wp_complain',             array(                 'name'=>$complain_name                                )         )==false) {         echo 'database insertion failed';     }     else {         echo 'database insertion successful';     } } else {     ?>     <form action="" method="post" role="form" class="form-horizontal">             name <input type="text" id="complain_name" class="form-control" name="complain_name" required="required" autocomplete="off"/>                          <input class="btn btn-block" id="submit" type="submit" value="submit" name="submit">          <div id="feedback"></div>     </form>      <script>         $(document).ready(function(e){              $("form").on('submit',(function(e) {                 e.preventdefault();                 //heresome other functions validation                      formdata =new formdata(this)                     $.ajax({                         url:'<?php echo content_url(); ?>/themes/abc/complain-detail.php',                         type: "post",                         data: formdata ,                         contenttype: false,                         cache: false,                         processdata:false,                         success: function(data)                         {                                                                $('#feedback').html(data)                                                        },                         error: function(data)                         {                             $('#feedback').html(data)                         }                     });                 }              ));          })     </script>      <?php } get_footer(); ?> 

use die("...."); instead of echo "...."; witch stop php code @ line, html won't shown.

if( isset($_post["submit"]) && !empty($_post["submit"]) ){        if(inserted)            die("database insertion successful"); //php stop here       else            die("database insertion failed"); //or here  }    //your html won't shown ... 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -