联系表单:解析错误

时间:2013-08-22 09:45:14

标签: php forms

我看不出我的错误。我要写一些文字。我的代码太多了? 我对这个问题很有压力。我是初学者,也许我工作太辛苦了。

<?php

    $n = array();

    if (!empty($_POST))
    {
        extract($_POST);
        $valid = true;

        if (empty($nom))
        {
            $valid = false;
            $erreur = 'Erreur nom';
            $n['erreurnom'] = true;
        }

        if (empty($email))
        {
            $valid = false;
            $erreur = 'Erreur email';
            $n['emailinvalide'] = false;
            $n['erreuremail'] = true;
        }
        elseif (!preg_match('/^[a-z0-9\-_.]+@[a-z0-9\-_.]+\.[a-z]{2,3}$/i', $email))
        {
            $valid = false;
            $erreur = 'Votre email n\'est pas valide';
            $n['erreuremail'] = false;
            $n['emailinvalide'] = true;
        }

        if (empty($message))
        {
            $valid = false;
            $erreur = 'Erreur message';
            $n['erreurmessage'] = true;
        }
    }
    else
    {
        $valid = false;
    }   
    $n['valide'] = $valid;
    echo json_encode($n);


    if ($valid = true)
    {
        $to = 'lalala@monmail.fr<script type="text/javascript">
    /* <![CDATA[ */
    (function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){})();
    /* ]]> */
    </script>';
        $sujet = $nom . ' a contacté le site';
        $header = 'From: $nom <$email> \n';
        $message = stripslashes($message);
        $nom = stripslashes($nom);

        if (mail($to, $sujet, $message, $header))
        {
            $erreur = 'Votre email nous est bien parvenu';
        }
        else
        {
            $erreur = 'Une erreur est survenue. Mail bloqué';
        }
        echo $erreur;
    }
?>

我的问题:parse error in "(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script") ....."

2 个答案:

答案 0 :(得分:1)

'[...]previousSibling;a=l.getAttribute(('data-cfemail')[...]'
                                        ^            ^
                                        here         and here

您在使用'打开的字符串中使用',您必须将其转义为\',如下所示:

'[...]previousSibling;a=l.getAttribute((\'data-cfemail\')[...]'

答案 1 :(得分:0)

你需要逃避:

的内容
getAttribute('data-cfemail');

添加斜杠

getAttribute(\'data-cfemail\');