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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号