dongpo2002 2017-01-23 00:05
浏览 36
已采纳

如何在联系表单下(或上方)返回reCaptcha

In a earlier question I got an answer from @ADyson of how to get the returns on a new blank page and that is in a way a solution, and thanks a lot for that. But I would prefer to get it under the contact form on that spesific contact page.I was told to do it with echo statement and if statement, but I am not smart enough to manage that. I use a web builder in the web host one.com. I enter the contact form in a code box on the contact page (I can not do corrections in the html-codes because it is over written next time I publish something with the web builder) an the php-file in the root of the file manager. I added echo statements to the returns in php, as you told me, and now the returns shows up on a blank page.That was my first goal, but as I said I would prefer to get it under the contact form.

Here is my form.php:

<?php
if(isset($_POST['submit']) && !empty($_POST['submit'])):
    if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
        //your site secret key
        $secret = 'secret key';
        //get verify response data
        $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
        $responseData = json_decode($verifyResponse);
        if($responseData->success):
            //contact form submission code
            $name = !empty($_POST['name'])?$_POST['name']:'';
            $email = !empty($_POST['email'])?$_POST['email']:'';
            $message = !empty($_POST['message'])?$_POST['message']:'';
            
            $to = 'kontakt@boakustikk.no';
            $subject = 'New contact form have been submitted';
            $htmlContent = "
                <h1>Henvendelse fra din hjemmeside</h1>
                <p><b>Navn: </b>".$name."</p>
                <p><b>E-post: </b>".$email."</p>
                <p><b>Melding: </b>".$message."</p>
            ";
            // Always set content-type when sending HTML email
            $headers = "MIME-Version: 1.0" . "
";
            $headers .= "Content-type:text/html;charset=UTF-8" . "
";
            // More headers
            $headers .= 'From:'.$name.' <'.$email.'>' . "
";
            //send email
            @mail($to,$subject,$htmlContent,$headers);

            echo$succMsg = 'TAKK FOR MELDING. VI KONTAKTER DEG SNAREST.';
        else:
            echo$errMsg = 'ROBOT VERIFIKASJON GIKK GALT, GÅ TILBAKE OG PRØV PÅ NYTT.';
        endif;
    else:
        echo$errMsg = 'MELDINGEN BLE IKKE SENDT. VENNLIGST GÅ TILBAKE OG KLIKK PÅ reCAPTCHA BOKS.';
    endif;
else:
    echo$errMsg = '';
    echo$succMsg = '';
endif;
?>

and here is my form.html:

<form action="form.php" method="POST">
    <input type="text" name="name"  placeholder="Ditt navn"  size="43" /><br><br>
    <input type="text" name="email" placeholder="Din E-post" size="43" /><br><br>
    <textarea type="text" name="message" rows="8" cols="41"></textarea><br><br>
    <div class="g-recaptcha" data-sitekey="site key"></div><br>
    <input type="submit" name="submit" value= "SEND MELDING">
</form>

I will be very happy to fix this issue.

BR Hans Kristian

</div>
  • 写回答

1条回答 默认 最新

  • dongsui8162 2017-01-29 19:59
    关注

    This case is now solved! If someone needs the codes for use on One.com web host server, please let me know.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败