Skip to main content

called function and ajax contact or mail function in wordpress

<?php
ob_start();
session_start();
/**

 * Plugin Name: Wps Custom
 * Plugin URI:
 * Description: custom plugin for all functions
 * Version: 1.0.1
 * Author: Webplanetsoft
 */




function wps_query_form()
{
  require_once('template/form.php');
}
function wps_query_contact()
{
  ob_start();
  require_once('template/contact.php');
  return ob_get_clean();
}
function wps_query_checkout()
{
  ob_start();
  require_once('template/checkout.php');
  return ob_get_clean();
}
function wps_query_mail2()
{
  if(isset($_POST['submit'])) {
   
   $ordernummer=$_REQUEST['ordernummer'];
    $email=$_REQUEST['email'];
    $kosten=$_REQUEST['kosten'];
    $beste=$_REQUEST['beste'];
    $ons=$_REQUEST['ons'];
    $besparing=$_REQUEST['besparing'];
  $baseurl = site_url()."/wp-content/plugins/wps_custom/image/"; 
  $content = file_get_contents(plugins_url( 'wps_custom/email/mail2.html', dirname(__FILE__) ));
   $body = wps_replace_string($content,array('[base_url]'=>$baseurl,
    '[ordernummer]'=>$ordernummer,'[kosten]'=>$kosten,'[beste]'=>$beste,'[ons]'=>$ons,'[besparing]'=>$besparing,'[email]'=>$email));


  add_filter( 'wp_mail_content_type', 'wps_set_html_content_type' ); 
  $to      = "$email";
  $subject = 'Check Out Page';
  wp_mail( $to, $subject, $body );
  remove_filter( 'wp_mail_content_type', 'wps_set_html_content_type' );
  echo "success";
  exit();


  }

  require_once('template/mail2.php');
}
function wps_home_form_callback()
{
  $req = $_REQUEST;
        $elektriciteit=$_POST['elektriciteit'];
  $gasverbruik=$_POST['gasverbruik'];
  $geen=$_POST['geen'];
  $fgroup=$_POST['fgroup'];
  $rtest=$_POST['rtest'];
  $fselect=$_POST['fselect'];
  $post_code=$_POST['post_code'];
  $huisnummer=$_POST['huisnummer'];
  $email=$_POST['email'];
  $groene=$_POST['groene'];
       
 $adminmail=get_option('admin_email');
        global $wpdb;

      $sql= "INSERT INTO wp_cform SET elektriciteit = '{$elektriciteit}',gasverbruik = '{$gasverbruik}',type_meter = '{$rtest}',leverancier = '{$fselect}',post_code = '{$post_code}',huisnummer = '{$huisnummer}',mail = '{$email}',groene_energie = '{$groene}'";
      $wpdb->query($sql);
      $lastid = $wpdb->insert_id;

        $baseurl = site_url()."/wp-content/plugins/wps_custom/image/"; 
  $content = file_get_contents(plugins_url( 'wps_custom/email/form.html', dirname(__FILE__) ));
   $body = wps_replace_string($content,array('[base_url]'=>$baseurl,
    '[elektriciteit]'=>$elektriciteit,'[gasverbruik]'=>$gasverbruik,'[geen]'=>$geen,'[fgroup]'=>$fgroup,'[rtest]'=>$rtest,'[fselect]'=>$fselect,'[post_code]'=>$post_code,'[huisnummer]'=>$huisnummer,'[email]'=>$email,'[groene]'=>$groene,'[order_id]'=>$lastid));


  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;
}
function wps_home_mail2_callback()
{  $to = "$adminmail";
  $from = $_POST['amail'];
  $ordernummer=$_POST['ordernummer'];
  $amail=$_POST['amail'];
  $kosten=$_POST['kosten'];
  $beste=$_POST['beste'];
  $ons=$_POST['ons'];
  $besparing=$_POST['besparing'];
  $subject1 = "Form submission";
  $subject12 = "Copy of your form submission";
  $message1 = $ordernummer . " " . $amail . " wrote the following:" .$kosten . $beste . $ons . $besparing;
  $message12 = "Here is a copy of your message ";

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "success";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
exit();
  }


add_shortcode('wps_query_form','wps_query_form');
add_shortcode('wps_query_contact','wps_query_contact');
add_shortcode('wps_query_mail2','wps_query_mail2');
add_shortcode('wps_query_checkout','wps_query_checkout');

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

add_action( 'wp_ajax_wps_contact_form', 'wps_contact_form_callback');
add_action('wp_ajax_nopriv_wps_contact_form', 'wps_contact_form_callback');

add_action( 'wp_ajax_wps_mail2_form', 'wps_contact_mail2_callback');
add_action('wp_ajax_nopriv_wps_mail2_form', 'wps_contact_mail2_callback');

add_action('admin_menu', 'admin_menu_item');   // add a new  menu item in admin panel
   
    function admin_menu_item(){
      
        add_menu_page('Ba-Users','Ba Users','administrator','ba_users','ba_users');
    }

    function ba_users(){
  
        echo do_shortcode('[wps_query_mail2]');
    }

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>


<script type="text/javascript">
$(document).ready(function(){
  $("#radio1").click(function(){
    $("#elektriciteit").val("1500");
    $("#gasverbruik").val("1000");
  });
  $("#radio2").click(function(){
    $("#elektriciteit").val("2600");
    $("#gasverbruik").val("1100");
  });
   $("#radio3").click(function(){
    $("#elektriciteit").val("3500");
    $("#gasverbruik").val("1500");
  });
   $("#radio4").click(function(){
    $("#elektriciteit").val("4500");
    $("#gasverbruik").val("1700");
  });
   $("#radio5").click(function(){
    $("#elektriciteit").val("5100");
    $("#gasverbruik").val("1800");
  });
$("#radio6").click(function(){
    $("#elektriciteit").val("0");
   
  });
$("#radio7").click(function(){
    $("#gasverbruik").val("0");
  });
});


</script>

















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

<!-- Fieldsets -->
<fieldset id="first">
<h2 class="title">Step 1:</h2>
<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>

<div class="col-md-2 col-sm-2 fradio">
<input type="radio" id="radio1" name="fgroup"  value="single">
<label for="radio1"><img src="<?php bloginfo('template_url'); ?>/images/single.png"> <p class="formimg">Single </p></label>
</div>
<div class="col-md-2 col-sm-2 fradio">
<input type="radio" id="radio2" name="fgroup" value="Samen">
<label for="radio2"><img src="<?php bloginfo('template_url'); ?>/images/samen.png"><p class="formimg">Samen</p></label>
</div>
<div class="col-md-2 col-sm-2 fradio">
<input type="radio" id="radio3" name="fgroup" value="Klein Gezin">
<label for="radio3"><img src="<?php bloginfo('template_url'); ?>/images/klein.png"><p class="formimg">Klein Gezin</p></label>
</div>
<div class="col-md-3 col-sm-3 fradio">
<input type="radio" id="radio4" name="fgroup" value="Middelgroot Gezin">
<label for="radio4"><img src="<?php bloginfo('template_url'); ?>/images/middelgroot.png"><p class="formimg">Middelgroot Gezin</p></label>
</div>
<div class="col-md-3 col-sm-3 fradio">
<input type="radio" id="radio5" name="fgroup" value="Groot Gezin">
<label for="radio5"><img src="<?php bloginfo('template_url'); ?>/images/groot.png"><p class="formimg">Groot Gezin</p></label>
</div>




<input class="next_btn" name="next" type="button" value="<?php _e( 'VERDER', 'bafreelance' ); ?>">
</fieldset>
<fieldset id="second">
<h2 class="title">Step 2:</h2>
<p class="subtitle">Heeft u een dubbele of enkele meter?</p>
<p class="subtitle">als de nachtstroom voor apart word gemeten, heeft u een dubbele meter.</p>
<p class="secondspan"><span id="radios-info" class="info"></span></p>
<div class="col-md-6 col-sm-6 vinr">
<input type="radio" id="radio11" name="rtest" value="Enkele Meter">
   <label for="radio1">Enkele Meter</label>

</div>
<div class="col-md-6 col-sm-6 vinr">
<input type="radio" id="radio11" name="rtest" value="Dubbele Meter">
   <label for="radio2">Dubbele Meter</label>
</div>



<input class="pre_btn" name="previous" type="button" value="<?php _e( 'TERUG', 'bafreelance' ); ?>">
<input class="next_btn" name="next" type="button" value="<?php _e( 'VERDER', 'bafreelance' ); ?>">
</fieldset>
<fieldset id="third">
<h2 class="title">Step 3:</h2>
<p class="subtitle">Uw overige gegevens.</p>
<p class="subtitle">Wij vragen uw postcode omdat energieprijzen verschillen per  regio.</p>
<div class="fselect">
<select name="fselect">
  <option value="Anode">Anode</option>
  <option value="Atoomstroom">Atoomstroom</option>
  <option value="BAS Nederland">BAS Nederland</option>
  <option value="Budget Energie">Budget Energie</option>
  <option value="Centrica Energy">Centrica Energy</option>
  <option value=" De Groene Belangenbehartiger">De Groene Belangenbehartiger</option>
  <option value="DELTA">DELTA</option>
  <option value="DONG Energy">DONG Energy</option>
  <option value=" E.ON">E.ON</option>
  <option value="Electrabel">Electrabel</option>
  <option value="Eneco">Eneco</option>
  <option value="Energie Data Maatschappij">Energie Data Maatschappij</option>
  <option value="Energiedirect.nl">Energiedirect.nl</option>
  <option value="EnergieFlex">EnergieFlex</option>
  <option value="ENGIE">ENGIE</option>
  <option value="Essent">Essent</option>
  <option value="Fenor">Fenor</option>
  <option value="Greinchoice">Greinchoice</option>
  <option value="Greenfoot">Greenfoot</option>
  <option value="Huismerk Energie">Huismerk Energie</option>
  <option value="HVC">HVC</option>
  <option value="Leon">Leon</option>
  <option value="MAIN Energie">MAIN Energie</option>
  <option value="Nederlandse Energie Maatschappij">Nederlandse Energie Maatschappij</option>
  <option value="Nieuwe Stroom">Nieuwe Stroom</option>
  <option value="Nuon">Nuon</option>
  <option value="Oxxio">Oxxio</option>
    <option value="Pure Energie">Pure Energie</option>
    <option value="Qurrent">Qurrent</option>
    <option value="Qwint">Qwint</option>
    <option value="Robin Energie">Robin Energie</option>
   <option value="UnitedConsumers">UnitedConsumers</option>
   <option value="Vandebron">Vandebron</option>

</select>
<p stitle>Uw postcode en husinummer</p>
<span id="post-info" class="info"></span><span id="w8d-info" class="info"></span>
<p class="postinput">
 
  <input  type="text" name="post_code" placeholder="1234 AA" maxlength="80" size="30" id="postinfo" class="postinfo"> <input  type="text" name="huisnummer" placeholder="123" maxlength="80" size="30" id="w8d"></p>
</div>

<input class="pre_btn" name="previous" type="button" value="<?php _e( 'TERUG', 'bafreelance' ); ?>">
<input class="next_btn" name="next" type="button" value="<?php _e( 'VERDER', 'bafreelance' ); ?>">
</fieldset>

<fieldset id="forth">

<h2 class="title">Step 4:</h2>
<p class="subtitle">Afronding van uw aanmeling</p>
<p><span id="email-info" class="info"></span></p>
<p class="lastf"> Uw e-mail adres <input  type="text" name="email" maxlength="80" size="30" id="femail"></p>
<p><span id="final-info" class="info"></span></p>
<p class="fqsn"> <p class="fcagree">Heeft u voorkeurvoor groene stroom ? <input type="radio" name="groene" value="ja" id="finalradio"> ja
  <input type="radio" name="groene" value="nee" id="finalradio"> Nee </p> </p>

 
<p><span id="terms-info" class="info"></span></p>
<p class="fagree"> <input type="checkbox" name="iagree" id="terms"> Ik ga akkoord met de <a href="<?php bloginfo('url'); ?>/algemene-voorwaarden">algemene voorwaarden</a>.</p>

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

  </fieldset>
</form>

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.' ?>