Skip to main content

Ajax Email or Contact form In Wordpress

Index.php Code

<?php


function wps_query_form()
{
    require_once('template/form.php');
}


function wps_home_form_callback()
{
    $req = $_REQUEST;
       


    add_filter( 'wp_mail_content_type', 'wps_set_html_content_type' );   
    $to      = "$adminmail,$email";
    $subject = 'Uw aanmelding bij BespaarAutomatisch.nl';   
    wp_mail( $to, $subject, $body );
    remove_filter( 'wp_mail_content_type', 'wps_set_html_content_type' );
    echo "success";
    exit();
}

function wps_set_html_content_type()
{
    return 'text/html';
}

function wps_replace_string($content,$aStrings)
{
    if($aStrings)
    {
        foreach($aStrings as $aKey => $aString)
        {
            $content = str_replace($aKey,$aString,$content);
        }
    }
   
    return $content;
}



add_action( 'wp_ajax_wps_home_form', 'wps_home_form_callback');
add_action('wp_ajax_nopriv_wps_home_form', 'wps_home_form_callback');


Form.php



<?php


?>


<script type="text/javascript">

jQuery(document).ready(function(){

 jQuery( ".vinr" ).click(function( event ) {

jQuery(this).find('input').prop('checked', true);



});


  jQuery( ".contactform" ).submit(function( event ) {

    url =  "<?php echo admin_url( 'admin-ajax.php' ); ?>"; 
    var data = jQuery( this ).serialize();
     jQuery.post(url, data, function(response) {
     if(response)
     {
      if(response == "success")
      {
        jQuery(".formMsg").html('Uw gegevens zijn succesvol verzonden.');
        setTimeout(function(){
           // location.reload(); 
        },3000);
      }
     }
   });
  return false;
  });
});



</script>




















<form name="contactform" method="post" class="contactform" id="contactform" action="#">
 <input type="hidden" name="action" value="wps_home_form" />
<!-- Progress Bar -->

<!-- Fieldsets -->

<p class="subtitle">Vult u eerst uw jaarverbruik in.</p>
<p class="subtitle">Als u het niet precies weet,kunt u de samenstelling van uw huishouden aanklikken.</p>
<div class="col-md-6 col-sm-6">

<p class="sfinput"><b> Elektriciteit </b><span class="fspan">kwh</span><input  type="text" name="elektriciteit" maxlength="50" size="30" id="elektriciteit" class="demoInputBox"> <span id="userName-info" class="info"></span> <p class="fcheck">  Geen Elektriciteit <input type="checkbox" name="geen" value="Geen Elektriciteit" id="radio6"> </p></p>
  </div>
  <div class="col-md-6 col-sm-6">
    <p class="sfinput"><b> Gasverbruik </b><span class="fspan">M3</span><input  type="text" name="gasverbruik" maxlength="50" size="30" id="gasverbruik"> <p class="fcheck">  Geen Gasverbruik <input type="checkbox" name="geen" value="Geen Gasverbruik" id="radio7"> </p></p>
  </div>


  <input  name="next" type="submit" value="<?php _e( 'VERSTUUR', 'bafreelance' ); ?>">
</fieldset>
<fieldset>
  <h1><div class="formMsg"></div> </h1>

  </fieldset>
</form>


form.html


<h1> hello </h1>

Comments

Popular posts from this blog

High light Search Result In Wordpress

High light Search Result In Wordpress add this function in your themes function.php function highlight_results ( $ text ) {      if ( is_search ( ) ) { $ keys = implode ( '|' , explode ( ' ' , get_search_query ( ) ) ) ; $ text = preg_replace ( '/(' . $ keys . ')/iu' , '<span class="search-highlight">\0</span>' , $ text ) ;      }      return $ text ; } add_filter ( 'the_content' , 'highlight_results' ) ; add_filter ( 'the_excerpt' , 'highlight_results' ) ; add_filter ( 'the_title' , 'highlight_results' ) ;   function highlight_results_css ( ) { ? > <style> .search-highlight { background-color : #FF0 ; font-weight : bold ; } </style> < ? php } add_action ( 'wp_head' , 'highlight_results_css' ) ;

Redirect In contact form 7

add_action( 'wp_footer' , 'redirect_cf7' ); function redirect_cf7() { ?> < script type = "text/javascript" > document.addEventListener( 'wpcf7mailsent' , function ( event ) { if ( '1377' == event.detail.contactFormId ) { // Sends sumissions on form 947 to the first thank you page location = 'https://www.panelesyceldassolares.com/regreso' ; } else { // Sends submissions on all unaccounted for forms to the third thank you page location = 'https://www.panelesyceldassolares.com/regreso-2/' ; } }, false ); </ script > <?php }

Get Single Product By ID in Opencart

<?php if(!empty($_POST["country_id"])) {     $query ="SELECT * FROM oc_product WHERE product_id = '" . $_POST["country_id"] . "'";     $results = $this->db->query($query);   $query2 ="SELECT * FROM oc_product_description WHERE product_id = '" . $_POST["country_id"] . "'";   $results2 = $this->db->query($query2);   $rowresults2 = $results2->row;   $rowresults = $results->row;   $name1 = $rowresults['model'];   $name2 = $rowresults2['name'];   $name3 = $rowresults['price'];   $name4 = 'Exe.' ?>