0

Form Captcha

    <script>
    function checkForm() {
    if (document.forms.myphpform.elements['yname'].value.length == 0) {
    alert('Please enter a value for the "Name" field');
    return false;
    }
    if (document.forms.myphpform.elements['email'].value.length == 0) {
    alert('Please enter a value for the "Email" field');
    return false;
    }
    if (document.forms.myphpform.elements['message'].value.length == 0) {
    alert('Please enter a value for the "Message" field');
    return false;
    }

    return true;
    }
    </script>


    <form action="?done=1" method="post" name="myphpform" onSubmit="return checkForm()" >
    <table border=0>
    <tr>
    <td>Your Name:</td> <td><input type="text" name="yname" size="50" maxlength="50" value="" /></td>
    </tr>

    <tr>
    <td>Your Email:</td> <td><input type="text" name="email" size="50" maxlength="50" value="" /></td>
    </tr>

    <tr>
    <td>Message:</td> <td><input type="text" name="message" size="50" maxlength="50" value="" /></td>
    </tr>
    <tr>
    <td>Are you a human being?</td>
    <td>
    <?php

    @require_once('recaptchalib.php');
    $publickey = "YOUR-PUBLIC-KEY";
    $privatekey = "YOUR-PRIVATE-KEY";

    $resp = null;
    $error = null;

    # are we submitting the page?
    if ($_POST["submit"]) {
    $resp = recaptcha_check_answer ($privatekey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);

    if ($resp->is_valid) {
    $to="davy_yg@yahoo.com";
    $subject="Feedback from Masterlink.co.id";
    $body=" Message via webform:

    Name: " .$_POST["yname"] . "\n

    Email: " .$_POST["email"] . "\n

    Message: " .$_POST["message"] . "\n";
    /* send email */
    mail($to,$subject,$body);
    echo "<p>Email sent!</p>";
    exit(1);

    } else {
    echo "Sorry cannot send email as you've failed to provide correct captcha! Try again...";
    }
    }
    echo recaptcha_get_html($publickey, $error);
    ?>
    <td/>
    </tr>
    <tr>
    <td> </td>
    <td><input type="submit" name="submit" value="submit" /></td>
    </tr>
    </table>
    </form>

Your Name:
Your Email:
Message:
Are you a human being?
Notice: Undefined index: submit in C:\xampp\htdocs\Rustoleum\konsultasi-konsumen.php on line 124
Input error: k: Format of site key was invalid

Line 124:  if ($_POST["submit"]) {

How to fix the problem ?

4
Contributors
58
Replies
60
Views
5 Years
Discussion Span
Last Post by davy_yg
0

the error message disappeared. The captcha picture does not eappear yet.

Your Name:
Your Email:
Message:
Are you a human being? Input error: k: Format of site key was invalid

1

Your public and private keys aren't valid for the domain. Go back to Recaptcha and create new ones for the current domain, or create universal public and private keys.

0

how to create new ones for the current domain or universal public and private keys?

0

It's too difficult. Maybe someone can help me on this one:

I include this codes in my form.

<?php 

    session_start();
    include("phpsimple/simple-php-captcha.php");
    $_SESSION['captcha'] = captcha();

    echo '<img src="' . $_SESSION['captcha']['image_src'] . '" alt="CAPTCHA" />';
?>

I wonder why the captcha does not appear.

It's a free script: simple-php-captcha-script

Demo page

Edited by pritaeas: Changed linked text

0

From the first link: "The only dependency is the PHP GD library." Do you have this one enabled?

Edited by pritaeas

0

It's too difficult

All you need to do is go to ReCaptcha enter your URL, and if you want universal keys, check a box. Then update your code to use the new keys.

What's difficult about filling in a field and ticking a box?

0

I've tried to recaptcha earlier get a downloaded file yet it asked me for a password. I do not know the password and do not get it in the email that I entered.

where to find the php.ini ?

0

ok, I tried using the goole recaptcha and still confuse how to customize it:

<script type="text/javascript"
     src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
</script>

<!-- Wrapping the Recaptcha create method in a javascript function -->
      <script type="text/javascript">
         function showRecaptcha(element) {
           Recaptcha.create("your_public_key", element, {
             theme: "red",
             callback: Recaptcha.focus_response_field});
         }
      </script>

<!-- ... your HTML <body> content ... -->

  <div id="recaptcha_div"></div>

  <input type="button" value="Show reCAPTCHA" onclick="showRecaptcha('recaptcha_div');"></input>

<?php

Recaptcha.destroy()
?>

Now, I have this:

[Show recaptcha]

Notice: Use of undefined constant Recaptcha - assumed 'Recaptcha' in C:\xampp\htdocs\Rustoleum\konsultasi-konsumen.php on line 99

Fatal error: Call to undefined function destroy() in C:\xampp\htdocs\Rustoleum\konsultasi-konsumen.php on line 99

I do not see the recaptcha images yet, only the button.

0

src="http://www.google.com/recaptcha/api/challenge?k=[you generated public key]">

Step 1: You have to signup to re-chaptcha and have to add/create a new domain to re-captcha/google from here:
-> http://www.google.com/recaptcha/whyrecaptcha
-> https://www.google.com/recaptcha/admin/create


Step 2: Then you will get 2 Information like api key and public key which you should place above where write[your public key]

It will work once you are developing it to your localhost/local server.


Hope this will make sense..
0

the recapca appear. Yet, after I enter the recaptcha information this error appears:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\Rustoleum\kontak_action.php on line 24
ERROR

why is it?

konsultasi-konsumen.php

<div id="form">
<form action="kontak_action.php" method="get">
<table border="0">
<tr align="left">
    <th>Nama&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</th>
    <th><input type="text" name="nama" size="25"/></th>
</tr>
<tr align="left">
    <th>Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</th>
    <th><input type="text" name="email" size="25" /></th>
</tr>
<tr align="left">
    <th>Telp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</th>
    <th><input type="text" name="telp" size="25" /></th>
</tr>
<tr align="left">
    <th>Komentar :</th>
    <th><textarea name="question" cols="30" rows="5"></textarea></th>
</tr>
<tr align="left">
    <th></th>
    <th><input type="submit" value="Submit" /></th>
</tr>
<tr>
<th><input type="button" value="Show reCAPTCHA" onclick="showRecaptcha('recaptcha_div');"></input></th>
<th><script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LdNVtMSAAAAAI-k_TFX4X_mICUsXJ3UAquWvuGl">
</script></th>
</th>
</tr>
</table>
</form> 

Edited by davy_yg

0

Failed to connect to mailserver at "localhost" port 25

If you use mail() on localhost, then most likely you did not install a mailserver.

0

Click Here

I just uploaded to the webserver. It works without the recaptcha. It doesn't work with the recaptcha. Yes, I do use mail() in kontak_action.php .

Edited by davy_yg

0

the mail form does work without the recaptcha. Now it doesn't work with the recaptcha. After I enter the data in the form and press submit it brings me to the next blank page.

Before I can receive all the input information.

kontak_action.php

<?php 
    $name       = $_REQUEST['nama'];
    $email      = $_REQUEST['email'];
    $telp       = $_REQUEST['telp'];
    $question   = $_REQUEST['question'];

    function HtmlSecure() {
        $_GET = array_map('htmlspecialchars' , $_GET);
        $_POST = array_map('htmlspecialchars' , $_POST);
        $_COOKIE = array_map('htmlspecialchars' , $_COOKIE);
    }

    HtmlSecure();

    $to = "davy_yg@yahoo.com";
    $subject = "Masterlink.co.id Contacts";
    $from = "info@masterlink.co.id";
    $body = "A visitor at masterlink.co.id has sent the following information\n
    Nama            : $name
    Email           : $email
    Telp            : $telp
    Pesan           : $question";

    if (mail($to, $subject, $body,"From: info@masterlink.co.id")) 
    {
       // header("location:../index.php?pg=Contacts&lang=$lang");

       echo "We've received your contact information";
    } 

    else
    {
        //header("location:../index.php?pg=Contacts&lang=$lang");

        echo "ERROR";
    }

?>

Edited by davy_yg

0

How to get the debug information? I am using dreamweaver for the code editors. Also, firefox for browser. I already installed firebug to see if it shows me somethings. It doesn't show me anything.

this is the url for the next blank page:

http://www.masterlink.co.id/kontak_action.php?nama=fsd&email=sfds&telp=fsdfsdf&question=fsdfsd&recaptcha_challenge_field=03AHJ_Vuuz7cCiXjqM8XGx4tjci87ig_VQ4xdNatbDOaKQ3Fcp5JQ0dx6fwp6prwlX7QdIdrTB82o_LlCaVUJgTLJtQVhhAudD-p5GBcf04uz3j5yJoz404Dk-ThRJE8KilP96q-YrFc6EzYQvEodcLicqpnXVym7kSA&recaptcha_response_field=calamity+hertais

I do not know whether it process the captcha information correctly.

0

where to write echo 'step X' ?

konsultasi-konsumen.php mostly coded in html

kontak-action.php written in php. and I already place the echo 'step X' in the beginning of the page, the next page after I input the form is a blank page.

konsultasi-konsumen.php

0

Well, one problem: without inputing the captcha information I also still receive the e-mail message.

This is the next page now: step XWe've received your contact information

0

I have this error: how to fix it?

Warning: require_once(recaptchalib.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\Rustoleum\konsultasi-konsumen.php on line 117

Fatal error: require_once() [function.require]: Failed opening required 'recaptchalib.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Rustoleum\konsultasi-konsumen.php on line 117

0

another error:

Notice: Undefined index: recaptcha_challenge_field in C:\xampp\htdocs\Rustoleum\konsultasi-konsumen.php on line 121

Notice: Undefined index: recaptcha_response_field in C:\xampp\htdocs\Rustoleum\konsultasi-konsumen.php on line 122
The reCAPTCHA wasn't entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)

line 121 & 122:
        $_POST["recaptcha_challenge_field"],
        $_POST["recaptcha_response_field"]);

This is the whole code underneath the form:

<?php
  require_once('recaptchalib.php');
  $privatekey = "your_private_key";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }
  ?>

Edited by davy_yg

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.