Advertisement
wendell_chrys

Plugin Wordpress Send Form

Sep 29th, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Formulario Cotação
  4. Plugin URI: http://solutionsagencia.com.br
  5. Description: Plugin para cotação em 2 passos.
  6. Version: 0.0.1
  7. Author: Wendell Christian
  8. Author URI: http://solutionsagencia.com.br
  9. License: GPLv2 or later
  10. License URI: http://www.gnu.org/licenses/gpl-2.0.html
  11. */
  12.  
  13.  
  14. // Verifica se não existe nenhum classe com o mesmo nome
  15. if ( ! class_exists('FormularioCotacao') ) {
  16.  
  17. class FormularioCotacao
  18. {
  19.  
  20.  
  21. /**
  22. * Este é o construtor da classe. Tudo aqui será executado quando o
  23. * plugin for ativado.
  24. */
  25. public function __construct() {
  26. /* Adiciona o shortcode */
  27. add_shortcode( 'cotacao', array( $this, 'ExibirTexto' ) );
  28. }
  29.  
  30. /**
  31. * Este é um método simples que irá exibir o texto do nosso shortcode
  32. */
  33. public function ExibirTexto () {
  34. $FormularioCotacaoURL = WP_CONTENT_URL;
  35. $FormularioCotacaoURL = WP_CONTENT_URL.'/plugins/'.plugin_basename( dirname(__FILE__)).'/';
  36. $urlsite = site_url();
  37. return "<div class='principal-form' id='principal-form'>
  38. <div class='col-md-35'><div class='titulo-inicie'>INICIE SUA COTAÇÃO AQUI</div></div>
  39. <form type='post' action='' id='cadastraForm'>
  40. <div class='col-md-65'><div class='col-md-34'><input type='text' name='nome' id='nome' class='campo-form' placeholder='Nome' maxlength='50'></div>
  41. <div class='col-md-34-2'><input type='email' name='email' id='email' class='campo-form' placeholder='Email' maxlength='120'/></div>
  42. <input type='hidden' name='action' value='addCustomer'/>
  43. <input type='hidden' name='urlsite' id='urlsite' value='".$urlsite."'/>
  44. <div class='col-md-30'><button type='submit' id='enviarform' class='botao-enviar'><span class='icone-cadastrar'></span>Efetue sua simulação</button>
  45. </form>
  46. </div>
  47. </div>
  48.  
  49. </div>
  50. <div id='feedback'></div>
  51. <div id='passo2form' class='passo2form'></div>
  52. <div class='col-md-100' id='botao-enviar-2'>
  53. <div class='col-md-70 margin-bottom-15 margin-top-15'><button type='submit' id='enviarform2' class='botao-enviar'><span class='icone-cadastrar'></span>Efetue sua simulação</button>
  54. </div></div>
  55.  
  56. ";
  57. }
  58.  
  59. }
  60.  
  61. /* Carrega a classe */
  62. $FormularioCotacao_settings = new FormularioCotacao();
  63.  
  64. } // class_exists
  65.  
  66.  
  67. function addCustomer(){
  68.  
  69. global $wpdb;
  70.  
  71. $nome = trim($_POST['nome']);
  72. $email = trim($_POST['email']);
  73.  
  74. if($wpdb->insert('wp_formclientes',array(
  75. 'nome'=>$nome,
  76. 'email'=>$email
  77. ))===FALSE){
  78.  
  79. echo "Error";
  80.  
  81. }
  82. else {
  83.  
  84. //mensagem de sucesso
  85.  
  86. }
  87. die();
  88.  
  89. }
  90. add_action('wp_ajax_addCustomer', 'addCustomer');
  91. add_action('wp_ajax_nopriv_addCustomer', 'addCustomer'); // not really needed
  92.  
  93.  
  94. /*Enviando email completo*/
  95.  
  96.  
  97. add_action('init', function(){
  98.  
  99. if ( isset( $_POST['cf-submitted'] ) ) {
  100.  
  101.  
  102. $nome = trim($_POST['nome']);
  103. $email = trim($_POST['email']);
  104. $comparar = ($_POST['comparar']);
  105. $tipo = ($_POST['tipo']);
  106. $telefone = ($_POST['telefone']);
  107. $profissao = ($_POST['profissao']);
  108. $zd = ($_POST['z-d']);
  109.  
  110.  
  111. $para = "wendell@solutionsagencia.com.br";
  112. $assunto = "Cotação em Compara Saúde" . $nome;
  113. $conteudo =
  114. "<b>Nome:</b> $nome" .
  115. "<br><b>Email:</b> $email" .
  116. "<br><b>Comparar:</b> $comparar" .
  117. "<br><b>Tipo:</b> $tipo" .
  118. "<br><b>Telefone:</b> $telefone" .
  119. "<br><b>Profissão:</b> $profissao" .
  120. "<br><b>0 a 18:</b> $zd";
  121.  
  122. $headers = array('Content-Type: text/html; charset=UTF-8',
  123. 'Reply-To' => $name . '<' . $email . '>');
  124.  
  125.  
  126.  
  127. $status = wp_mail( $para, $assunto, $conteudo, $headers );
  128.  
  129. if ( $status ){
  130. echo "";
  131. } else {
  132. echo "erro";
  133. }
  134.  
  135.  
  136. }
  137.  
  138. });
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150. function FormularioCotacao_addJS() {
  151. $FormularioCotacaoURL = WP_CONTENT_URL.'/plugins/'.plugin_basename( dirname(__FILE__)).'/';
  152. wp_register_script('processa', $FormularioCotacaoURL . 'js/processa.js');
  153. wp_register_style('estilo', $FormularioCotacaoURL . 'css/estilo.css');
  154. wp_enqueue_style('estilo', $FormularioCotacaoURL . 'css/estilo.css');
  155. wp_enqueue_script('processa', $FormularioCotacaoURL . 'js/processa.js', array ( 'jquery' ), 1.12, true);
  156. wp_localize_script('processa', 'UrlCotacao', array('pluginsUrl' => plugins_url(),));
  157. }
  158.  
  159. add_action('wp_print_scripts', 'FormularioCotacao_addJS');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement