0

I have a problem, I am using custom theme on my magento site, and use this script. It works only in RWD theme. I try to find some information about it and don't find anything.Please help if you know something to help me to work this script in default theme.When i click submit in this form, write "Enter a valid email address". In RWD theme this code work fine.

<div class="block block-subscribe">
<div class="block-title">
    <strong><span><?php echo $this->__('Newsletter') ?></span></strong>
</div>
<div id="feedback" style="display:none" class="mini-newsletter">
    Thank you for subscribing to our newsletter!
</div>
<form action="<?php echo $this->getFormActionUrl() ?>" name="newsletter-form" id="newsletter-form" method="post">
    <div class="block-content">
        <div class="form-subscribe-header">
            <label for="newsletter"><?php echo $this->__('Sign Up for Our Newsletter:') ?></label>
        </div>
        <div class="input-box">
            <input type="text" placeholder="Email address" name="email" id="newsletter" title="<?php echo $this->__('Subscribe to Our Newsletter') ?>" class="required-entry input-subscribe" style="width:178px;" />
            <div class="error-news-msg" id="error-news-msg" style="display:none;">Please enter a valid email address.</div>
        </div>
        <div class="actions">
            <button type="button" title="<?php echo $this->__('Subscribe') ?>" onclick="myfunc();" class="button">
                <span><span>Subscribe</span></span>
            </button>
        </div>
    </div>
</form>

<script type="text/javascript">
function myfunc()
{
    var newsletterSubscriberFormDetail = new VarienForm('newsletter-form');
    var form_email = $('newsletter').getValue();
    var params_form = $('newsletter-validate-detail');
    //alert(params_form);
    if(echeck(form_email))
    {
        //alert(form_email);
        //alert(Form.serialize($('newsletter-validate-detail')));
        new Ajax.Updater({ success: 'newsletter-form' }, '<?php echo $this->getUrl('newsletter/subscriber/new') ?>', {
            asynchronous:true, evalScripts:false,
            parameters: { email: form_email },
            onComplete:function(request, json){Element.hide('newsletter-form');Element.show('feedback');},
            onLoading:function(request, json){Element.hide('news-loader');}

        });



    }
    else
    {
        //alert(form_email);
        return false;
    }

}



function echeck(str) {

    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    if (str.indexOf(at)==-1){
        //alert("Invalid E-mail ID")
        goProcedural();
        return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        //alert("Invalid E-mail ID")
        goProcedural();
        return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        //alert("Invalid E-mail ID")
        goProcedural();
        return false
    }

    if (str.indexOf(at,(lat+1))!=-1){
        //alert("Invalid E-mail ID")
        goProcedural();
        return false
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        //alert("Invalid E-mail ID")
        goProcedural();
        return false
    }

    if (str.indexOf(dot,(lat+2))==-1){
        //alert("Invalid E-mail ID")
        goProcedural();
        return false
    }

    if (str.indexOf(" ")!=-1){
        //alert("Invalid E-mail ID")
        goProcedural();
        return false
    }

    return true
}

function goProcedural()
{
    Element.show('error-news-msg');
    Element.hide.delay(5, 'error-news-msg');
}

0

Where is the script located? Is it a separate .js file or part of .phtml?

  1. If it's a .js check layout.xml for the theme and register it there.

  2. If it's part of .phtml, open the page where it should be loaded and inspect if it's leing loaded at all, if not, you wrote it in the wrong file.

Please comment the full path of the file if none of this works.

  • This code located in my custom form app/design/frontend/mycustomtheme/default/template/newsletter/subscribe-custom-form.phtml......at page all code is loaded and there is no some error's. – Сергей Коржевский Aug 17 '16 at 15:27
  • I see that the entire code is a few JS functions, are you calling them anywhere? If so, try opening the console and calling them from there, see if you get any errors. – Radosav Aug 17 '16 at 15:37
  • In the console is no error's. When i click submit in this form, write "Enter a valid email address".But in rwd theme work fine – Сергей Коржевский Aug 17 '16 at 19:07
  • Did you try going to the console and writing "myfunc()" ? – Radosav Aug 18 '16 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.