jcadima
10/12/2017 - 9:31 PM

Complete Magento recaptcha - INVISIBLE

Complete Magento recaptcha - INVISIBLE

<?php
// ======================= send_contact.php ==============================
<?php

require 'PHPMailerAutoload.php';
require_once 'Recaptcha.php';
// require_once dirname(__FILE__) . '/Recaptcha.php';
if ( ! class_exists('Recaptcha') ) 
  die('Class Recaptcha not found') ; 

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
$recaptcha = $_POST['g_recaptcha_response'];

/*
echo '<pre>';
echo 'POST<br>';
print_r($_POST) ;
echo '</pre>';
*/


$cleanarray = array(); 


$current_date = date('n/j/Y'); 
$current_time = date('g:i a') ;
$recobj = new Recaptcha();
$response = $recobj->verifyResponse($recaptcha);

if( isset($response['success']) && $response['success'] != true )  {
	echo "An Error Occurred and Error code is :".$response['error-codes'];
}
else {

	$mail = new PHPMailer;
	
	// $mail->SMTPDebug = 3;                               // Enable verbose debug output
	
	$mail->isSMTP();                                      // Set mailer to use SMTP
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->SMTPSecure = "tls";                 // sets the prefix to the servier
	// $mail->Host       = "mail.smtp2go.com ";      // sets GMAIL as the SMTP server
	$mail->Host       = "smtp.gmail.com ";      // sets GMAIL as the SMTP server
	$mail->Port       = 587;                   // set the SMTP port for the GMAIL server
	$mail->Username   = "juan@popcreativegroup.com";  // GMAIL username
	$mail->Password   = "popjuan7480#";                              
	
	$mail->setFrom('admin@popbetaserver.com', 'IGM Contact Form');
	$mail->addReplyTo('jcadima85@gmail.com', 'reply to');
	$mail->addAddress( 'juan@popcreativegroup.com', 'JC');     // Add a recipient
	
	$mail->isHTML(true);                                  // Set email format to HTML
	
	$mail->Subject = 'New Message' ;
	$mail->Body    = "
    ==================================== <br>
    CONTACT US - NEW MESSAGE<br>
    Date: $current_date Time:  $current_time<br>
    ====================================<br>
    
    <strong>Name:</strong> $name<br>
    <strong>Email:</strong> $email<br>
    <strong>Phone:</strong>   $phone<br>
    <strong>Comment:</strong>   $comment<br>" 
    ;
	
	// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
	
	if(!$mail->send() ) {
	    echo 'Message could not be sent.';
	    //echo 'Mailer Error: ' . $mail->ErrorInfo;
	} else {
	    echo 'Message has been sent';
	}	
	
}


// ===== 1column-contact.phtml ============

<?php
/**
 * Template for Mage_Page_Block_Html
 */
?>
<?php
$store = Mage::app()->getStore();
$code  = $store->getCode();
$bodyClass = $this->getBodyClass()? $this->getBodyClass():'';
$bodyClass .= ' '.Mage::getStoreConfig('granada_setting/general_settings/page_style',$code);
$bodyClass .= ' '.(Mage::getStoreConfig('granada_setting/general_settings/is_responsive',$code)==1)?'':' non-responsive';
?>

<!DOCTYPE html>
<html lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<!--  /smartwave/granada/template/page/1column-contact.phtml   -->
<body class="<?php echo $bodyClass ?>">
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper">
    <?php echo $this->getChildHtml('global_notices') ?>
    <div class="page">
        <?php echo $this->getChildHtml('header') ?>
        
 <div class="row display_flex">

<div class="container">        
        <div id="banner_container_left"  class="col-md-6">
			<div class="map-responsive">
				<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3594.165775661665!2d-80.26295264891452!3d25.73203088357002!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x88d9b7eea610f9d7%3A0x76128e6b25acd31e!2s330+San+Lorenzo+Ave+%232327%2C+Coral+Gables%2C+FL+33146!5e0!3m2!1sen!2sus!4v1504707401550" width="800" height="600" frameborder="0" style="border:0" allowfullscreen></iframe>	
			</div>		
    
    	</div>
        

        <div id="banner_container_right" class="col-md-6" style="background:url(<?php  echo $this->getLayout()->createBlock('cms/block')->setBlockId('contact_img_right')->toHtml();  ?>);">

	        <div class="banner_right">
				<h4 class="cta_title">SEND US A MESSAGE</h4>


		
		         <form action="" id="cta_form" method="post">
		            <div class="fieldset">
          
                        <div class="input-box">
                            <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry big-input-text" type="text" placeholder="Name">
                        </div>
		            		                   		                 	                      
                        <div class="input-box">
                            <input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email big-input-text" type="text" placeholder="Email">
                        </div>

		                    
                        <div class="input-box">
                            <input name="phone" id="phone" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text big-input-text" type="text" placeholder="Phone">
                        </div>
        
				                   		                
                        <div class="input-box">
                            <textarea name="comment" id="comment" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text big-input-text min-height" cols="5" rows="2"></textarea>
                        </div>

		            </div>
		            
		            <div class="buttons-set">
		             <!--    <p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>  -->
		                <input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
		                
		                <!--
		                <button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button cta-button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
		                -->

				<button class="g-recaptcha" 
				        data-sitekey="6Lfi5B8UAAAAAGqVZbrz7-NHEEzn0SUBjL6l7wYD" 
				        data-callback="onSubmit" 
				        id="ajaxsubmit"
				        type="submit" 
				        value="Submit">Send
				</button>
			
		                              		                
		            </div>
		        </form>
		
				
				 <div id="loader" class="col-md-12" style="display:none;">
				   
				    <img src="http://popbetaserver.com/projects/igm/media/wysiwyg/spinner.gif">
				 </div>							
				
				 <div class="col-md-12 text-center">
				 	<div id="result" class="alert alert-success" style="display:none;"></div>
				 </div>
		

	        </div>
	      
        </div>    
        
	</div>
               
        
 </div>     
        
        
        
        <div class="main-container col1-layout container">
            <div class="main">
                <div class="row">

                    <?php echo $this->getChildHtml('category.top.banner') ?>
                    <div class="col-main col-xs-12">
                        <?php echo $this->getChildHtml('global_messages') ?>
                        <?php echo $this->getChildHtml('content') ?>
                    </div> 
                </div>
            </div>
        </div>
        <?php echo $this->getChildHtml('footer') ?>
        <?php echo $this->getChildHtml('global_cookie_notice') ?>
        <?php echo $this->getChildHtml('before_body_end') ?>
    </div>
</div>
<?php echo $this->getChildHtml('page.totop') ?>
<?php echo $this->getAbsoluteFooter() ?>


<script>
//jQuery(document).ready(function() {
	// jQuery("#cta_form").submit(function(event) {
	function onSubmit() {
	    jQuery('#loader').show() ; // show the loader on init
	    /* Stop form from submitting normally */
	    event.preventDefault();
		var name = jQuery('#name').val();
		var email = jQuery('#email').val();
		var phone = jQuery('#phone').val();
		var comment = jQuery('#comment').val();
	    var g_recaptcha_response  = jQuery('#g-recaptcha-response').val();
	    var currenturl = jQuery('#currenturl').val();
	    // var values = jQuery(this).serialize();

	    /* Clear result div*/
	    jQuery("#result").html('');
	    
	    ajaxRequest = jQuery.ajax({
	       url: "<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>send_contact.php",
	       type: "post",
	       data: {name:name, email:email, phone:phone, comment:comment, g_recaptcha_response }
	      
	    });
	    
	    /*  request cab be abort by ajaxRequest.abort() */
	    ajaxRequest.done(function (response, textStatus, jqXHR){
	       // show successfully for submit message
	       console.log("SUCCESS") ;
	       jQuery('#result').show() ;
	       jQuery("#result").html(response);
	       jQuery('#loader').hide() ; // ajax successful , hide the loader
          
	    });
	    /* On failure of request this function will be called  */
	    ajaxRequest.fail(function (response){
	       // show error
	       console.log(" ajax fail ERROR" + response) ;
	       jQuery("#result").html('Error found trying to submit the form: ' + response );
	    });
	}

	//});

// }); // end document ready
</script>


<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>

<script src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>js/form_validation.js"></script>



</body>
</html>