Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento - Validate Email in Database with AJAX without refresh
    primarykey
    data
    text
    <p>I’m beginner in Magento and I’m with a QuickCheckout Form, where I need to validate the e-mail field. </p> <p>When the user put the e-mail on the field I need to search in the database (table customer_entity) the e-mail dynamically, without refresh </p> <p>I have code using Ajax.Request that works to validate the writing of e-mail using regular expressions </p> <pre><code>function validar_email() { local = "billing"; var urlAjax = location.href; var validarUrl = /^https:\/\//; if ( urlAjax.match( validarUrl ) ) { urlAjax = '&lt;?php echo Mage::getBaseUrl("link", true)."ajaxend/ajax" ?&gt;'; } else { urlAjax = '&lt;?php echo $this-&gt;getUrl("ajaxend/ajax") ?&gt;'; } new Ajax.Request( urlAjax, {method: 'POST', parameters: 'email='+$(local+':email').value, evalScripts: true, onLoading: function(transport) { $('load-email-'+local).innerHTML = 'Verificando E-mail'; }, onSuccess: function(transport) { var emailReg = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/; var emailValido = 'E-mail Válido'; var emailInvalido = 'E-mail Inválido, digite outro'; if( !emailReg.test($(local+':email').value)){ $('load-email-'+local).innerHTML = emailInvalido; } else { $('load-email-'+local).innerHTML = emailValido; } }, onComplete: function(transport) { }, onFailure: function() { /*document.getElementById("...").innerHTML = 'problemas...';*/ } }); } </code></pre> <p>I made two pieces of code to search in Database: Code 1: </p> <pre><code>$email = $_POST['email']; $resource = Mage::getSingleton('core/resource'); $readConnection = $resource-&gt;getConnection('core_read'); $table = $resource-&gt;getTableName('customer_entity'); $query = 'SELECT email FROM ' . $table . ' WHERE email = "'.$email.'";'; $sku = $readConnection-&gt;fetchAll($query); </code></pre> <p>Code 2 (only PHP): </p> <pre><code>$queryVerifEmail = ''; $queryVerifEmail .= ' SELECT email FROM customer_entity'; $queryVerifEmail .= ' WHERE email = "'.$email.'";'; $result = mysql_query($queryVerifEmail); </code></pre> <pre><code>if(mysql_num_rows($result) &gt; 1){ echo $email.' já existe na base!'; } else{ echo $email.'valido'; } </code></pre> <p>I tried to make referenced php files in the line </p> <pre><code>new Ajax.Request( "getEmail.php?", {method: 'GET', </code></pre> <p>And nothing works, but Ajax.Request is the only way to make working Inputs without refresh in Magento </p> <p>I want to have the best solution that you know, but I don´t want to buy or install new modules for it, I want a code solution, be in Ajax, JQuery or PHP. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload