0

Parse error: syntax error, unexpected $end in /home/sloki/user/masterli/sites/masterlink.co.id/www/kontak_action.php on line 88

konsultasi-konsumen.php

kontak-action.php

<?php 

echo 'step X';

$nama = check_input($_POST['nama'], "Enter your name");
$email    = check_input($_POST['email'], "Enter your email");
$telp   = check_input($_POST['telp'], "Enter your phone number");
$questions = check_input($_POST['questions'], "Write your comments");
?>

Your name is: <?php echo $nama; ?><br />
Your e-mail: <?php echo $email; ?><br />
Your phone: <?php echo $telp; ?><br />
Your comments: <?php echo $questions; ?><br />

<br />

<?php

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    show_error("E-mail address not valid");
}

function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        die($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
<?php echo $myError; ?>

<?php /* end */ ?>


<?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";
    }

?>

Line 88 is the last line. What else do I need to fix? I basically need to validate the form for required field besides the captcha.

Thanks.

0

Now, evenif I left the whole form blank only this message appears in the next page:

step XEnter your name

It suppose to disallow me to go to the next page and show me the errors next to the form if I left one of the form blank.

0

It suppose to disallow me to go to the next page and show me the errors next to the form if I left one of the form blank.

If you want to stop the form from submitting, you will need a Javascript solution, or redirect back to the form, passing the error in the URL (then you need to save the form's data too).

Edited by pritaeas

0

If you want to stop the form from submitting, you will need a Javascript solution, or redirect back to the form, passing the error in the URL (then you need to save the form's data too).

Disagree.

Why can you not build the form so that it submits to itself (same script) and performs server-side validation. If there are errors, redisplay the form with inline error messages. If there are no errors, send the email and redirect to the next page.

??

Edited by blocblue

1

Okay, so you clearly seem to be struggling seeing as this thread has been running for a month now.

In which case, lets approach it from a different angle. I've quickly put together an example form (with minimal validation), which I think does what you're after. It submits to itself, and doesn't redirect to another page until the form is valid and an email notification sent.

<?php

// Include ReCaptcha and define keys
require_once('recaptcha.php');
define('RECAPTCHA_PUBLIC', '6Lc1ntQSAAAAAAxrl-iJui8kXgFAUemdhcbV38hl');
define('RECAPTCHA_PRIVATE', '6Lc1ntQSAAAAAOIcduLKmNVXGTz1ddZ6AZyzGfl6');

// Define notification recipient
define('NOTIFICATION_RECIPIENT', 'davy_yg@yahoo.com');

// Define data and error arrays
$data = array('name' => '', 'email' => '', 'message' => '');
$errors = array();
$error = '';

// Check if form submitted
if($_POST) {
    // Prepare form data and captcha 
    $data = array_merge($data, $_POST['form']);
    $captcha = recaptcha_check_answer(RECAPTCHA_PRIVATE, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);

    // Validate name
    if(strlen(trim($data['name'])) == 0)
        $errors['name'] = 'Name is mandatory';

    // Validate email
    if(strlen(trim($data['email'])) == 0)
        $errors['email'] = 'Email is mandatory';
    elseif(! filter_var($data['email'], FILTER_VALIDATE_EMAIL))
        $errors['email'] = 'Email is not valid';

    // Validate message
    if(strlen(trim($data['message'])) == 0)
        $errors['message'] = 'Message is mandatory';

    // Validate captcha
    if(! $captcha->is_valid)
        $errors['captcha'] = 'Captcha is incorrect';

    // Send email and redirect user if no form errors
    if(! $errors) {
        if(send_notification($data))
            header('Location: thank-you.php');
        else
            $error = 'An unexpected error occurred. Please try again.';
    }
}
?>
<html>
    <head>
        <title>Example Form</title>
    </head>

    <body>
        <form method="post" action="form.php">
            <?php if($error): ?>
                <h3><?php echo $error; ?></h3>
            <?php endif; ?>

            <div class="form-row">
                <label for="name">Name</label><br />
                <input id="name" type="text" name="form[name]" value="<?php echo $data['name']; ?>" />

                <?php if(isset($errors['name'])): ?>
                    <span class="form-error"><?php echo $errors['name']; ?></span>
                <?php endif; ?>
            </div>

            <div class="form-row">
                <label for="email">Email</label><br />
                <input id="email" type="text" name="form[email]" value="<?php echo $data['email']; ?>" />

                <?php if(isset($errors['email'])): ?>
                    <span class="form-error"><?php echo $errors['email']; ?></span>
                <?php endif; ?>
            </div>

            <div class="form-row">
                <label for="message">Message</label><br />
                <textarea id="message" name="form[message]"><?php echo $data['message']; ?></textarea>

                <?php if(isset($errors['message'])): ?>
                    <span class="form-error"><?php echo $errors['message']; ?></span>
                <?php endif; ?>
            </div>

            <div class="form-row">
                <?php echo recaptcha_get_html(RECAPTCHA_PUBLIC); ?>

                <?php if(isset($errors['captcha'])): ?>
                    <span class="form-error"><?php echo $errors['captcha']; ?></span>
                <?php endif; ?>
            </div>

            <div class="form-row">
                <input type="submit" value="Submit" />
            </div>
        </form>
    </body>
</html>
<?php
/**
 * Send contact form notification.
 *
 * @param array $data
 * @return boolean
 */
function send_notification(array $data)
{
    // Prepare headers
    $headers = implode("\n", array(
        "From: no-reply@masterlink.co.id",
        "Reply-To: {$data['email']}",
        'MIME-Version: 1.0',
        'Content-type: text/plain; charset=utf-8',
    ));

    // Prepare recipient and subject
    $subject = 'New website enquiry';

    // Prepare body
    $body = <<<EOD
A visitor at masterlink.co.id has sent the follow information:
Name: {$data['name']}
Email {$data['email']}
Message:
{$data['message']}
EOD;

    return mail(NOTIFICATION_RECIPIENT, $subject, $body, $headers);
}

If it helps, read through the code, try to understand it, and come back with specific questions.

The ReCaptcha keys should work on all domains, so shouldn't need changing.

Hope this helps you, or someone else.

0

I receive this error message:

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Rustoleum\konsultasi-konsumen2.php on line 169

line 169 is 2 lines after the last code.

0
    <?php
    // Include ReCaptcha and define keys
    require_once('recaptcha.php');
    define('RECAPTCHA_PUBLIC', '6Lc1ntQSAAAAAAxrl-iJui8kXgFAUemdhcbV38hl');
    define('RECAPTCHA_PRIVATE', '6Lc1ntQSAAAAAOIcduLKmNVXGTz1ddZ6AZyzGfl6');
    // Define notification recipient
    define('NOTIFICATION_RECIPIENT', 'davy_yg@yahoo.com');
    // Define data and error arrays
    $data = array('name' => '', 'email' => '', 'message' => '');
    $errors = array();
    $error = '';
    // Check if form submitted
    if($_POST) {
    // Prepare form data and captcha
    $data = array_merge($data, $_POST['form']);
    $captcha = recaptcha_check_answer(RECAPTCHA_PRIVATE, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
    // Validate name
    if(strlen(trim($data['name'])) == 0)
    $errors['name'] = 'Name is mandatory';
    // Validate email
    if(strlen(trim($data['email'])) == 0)
    $errors['email'] = 'Email is mandatory';
    elseif(! filter_var($data['email'], FILTER_VALIDATE_EMAIL))
    $errors['email'] = 'Email is not valid';
    // Validate message
    if(strlen(trim($data['message'])) == 0)
    $errors['message'] = 'Message is mandatory';
    // Validate captcha
    if(! $captcha->is_valid)
    $errors['captcha'] = 'Captcha is incorrect';
    // Send email and redirect user if no form errors
    if(! $errors) {
    if(send_notification($data))
    header('Location: thank-you.php');
    else
    $error = 'An unexpected error occurred. Please try again.';
    }
    }
    ?>
    <html>
    <head>
    <title>Example Form</title>
    </head>
    <body>
    <form method="post" action="form.php">
    <?php if($error): ?>
    <h3><?php echo $error; ?></h3>
    <?php endif; ?>
    <div class="form-row">
    <label for="name">Name</label><br />
    <input id="name" type="text" name="form[name]" value="<?php echo $data['name']; ?>" />
    <?php if(isset($errors['name'])): ?>
    <span class="form-error"><?php echo $errors['name']; ?></span>
    <?php endif; ?>
    </div>
    <div class="form-row">
    <label for="email">Email</label><br />
    <input id="email" type="text" name="form[email]" value="<?php echo $data['email']; ?>" />
    <?php if(isset($errors['email'])): ?>
    <span class="form-error"><?php echo $errors['email']; ?></span>
    <?php endif; ?>
    </div>
    <div class="form-row">
    <label for="message">Message</label><br />
    <textarea id="message" name="form[message]"><?php echo $data['message']; ?></textarea>
    <?php if(isset($errors['message'])): ?>
    <span class="form-error"><?php echo $errors['message']; ?></span>
    <?php endif; ?>
    </div>
    <div class="form-row">
    <?php echo recaptcha_get_html(RECAPTCHA_PUBLIC); ?>
    <?php if(isset($errors['captcha'])): ?>
    <span class="form-error"><?php echo $errors['captcha']; ?></span>
    <?php endif; ?>
    </div>
    <div class="form-row">
    <input type="submit" value="Submit" />
    </div>
    </form>
    </body>
    </html>
    <?php
    /**
    * Send contact form notification.
    *
    * @param array $data
    * @return boolean
    */
    function send_notification(array $data)
    {
    // Prepare headers
    $headers = implode("\n", array(
    "From: no-reply@masterlink.co.id",
    "Reply-To: {$data['email']}",
    'MIME-Version: 1.0',
    'Content-type: text/plain; charset=utf-8',
    ));
    // Prepare recipient and subject
    $subject = 'New website enquiry';
    // Prepare body
    $body = <<<EOD
    A visitor at masterlink.co.id has sent the follow information:
    Name: {$data['name']}
    Email {$data['email']}
    Message:
    {$data['message']}
    EOD;
    return mail(NOTIFICATION_RECIPIENT, $subject, $body, $headers);
    }
?>

Line 169 is two lines after the last line.

Edited by davy_yg

0

If it's two lines after the end of the file, can you post the code in recaptcha.php too?

And to aid readability, can you indent the code please?

0

it suppose to be recaptchalib.php

I already changed it and the same error still appears.

recaptchalib.php

<?php
/*
 * This is a PHP library that handles calling reCAPTCHA.
 *    - Documentation and latest version
 *          http://recaptcha.net/plugins/php/
 *    - Get a reCAPTCHA API Key
 *          https://www.google.com/recaptcha/admin/create
 *    - Discussion group
 *          http://groups.google.com/group/recaptcha
 *
 * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
 * AUTHORS:
 *   Mike Crawford
 *   Ben Maurer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/**
 * The reCAPTCHA server URL's
 */
define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
define("RECAPTCHA_VERIFY_SERVER", "www.google.com");

/**
 * Encodes the given data into a query string format
 * @param $data - array of string elements to be encoded
 * @return string - encoded request
 */
function _recaptcha_qsencode ($data) {
        $req = "";
        foreach ( $data as $key => $value )
                $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';

        // Cut the last '&'
        $req=substr($req,0,strlen($req)-1);
        return $req;
}



/**
 * Submits an HTTP POST to a reCAPTCHA server
 * @param string $host
 * @param string $path
 * @param array $data
 * @param int port
 * @return array response
 */
function _recaptcha_http_post($host, $path, $data, $port = 80) {

        $req = _recaptcha_qsencode ($data);

        $http_request  = "POST $path HTTP/1.0\r\n";
        $http_request .= "Host: $host\r\n";
        $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
        $http_request .= "Content-Length: " . strlen($req) . "\r\n";
        $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
        $http_request .= "\r\n";
        $http_request .= $req;

        $response = '';
        if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
                die ('Could not open socket');
        }

        fwrite($fs, $http_request);

        while ( !feof($fs) )
                $response .= fgets($fs, 1160); // One TCP-IP packet
        fclose($fs);
        $response = explode("\r\n\r\n", $response, 2);

        return $response;
}



/**
 * Gets the challenge HTML (javascript and non-javascript version).
 * This is called from the browser, and the resulting reCAPTCHA HTML widget
 * is embedded within the HTML form it was called from.
 * @param string $pubkey A public key for reCAPTCHA
 * @param string $error The error given by reCAPTCHA (optional, default is null)
 * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)

 * @return string - The HTML to be embedded in the user's form.
 */
function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
{
    if ($pubkey == null || $pubkey == '') {
        die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
    }

    if ($use_ssl) {
                $server = RECAPTCHA_API_SECURE_SERVER;
        } else {
                $server = RECAPTCHA_API_SERVER;
        }

        $errorpart = "";
        if ($error) {
           $errorpart = "&amp;error=" . $error;
        }
        return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>

    <noscript>
        <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
    </noscript>';
}




/**
 * A ReCaptchaResponse is returned from recaptcha_check_answer()
 */
class ReCaptchaResponse {
        var $is_valid;
        var $error;
}


/**
  * Calls an HTTP POST function to verify if the user's guess was correct
  * @param string $privkey
  * @param string $remoteip
  * @param string $challenge
  * @param string $response
  * @param array $extra_params an array of extra variables to post to the server
  * @return ReCaptchaResponse
  */
function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
{
    if ($privkey == null || $privkey == '') {
        die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
    }

    if ($remoteip == null || $remoteip == '') {
        die ("For security reasons, you must pass the remote ip to reCAPTCHA");
    }



        //discard spam submissions
        if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
                $recaptcha_response = new ReCaptchaResponse();
                $recaptcha_response->is_valid = false;
                $recaptcha_response->error = 'incorrect-captcha-sol';
                return $recaptcha_response;
        }

        $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
                                          array (
                                                 'privatekey' => $privkey,
                                                 'remoteip' => $remoteip,
                                                 'challenge' => $challenge,
                                                 'response' => $response
                                                 ) + $extra_params
                                          );

        $answers = explode ("\n", $response [1]);
        $recaptcha_response = new ReCaptchaResponse();

        if (trim ($answers [0]) == 'true') {
                $recaptcha_response->is_valid = true;
        }
        else {
                $recaptcha_response->is_valid = false;
                $recaptcha_response->error = $answers [1];
        }
        return $recaptcha_response;

}

/**
 * gets a URL where the user can sign up for reCAPTCHA. If your application
 * has a configuration page where you enter a key, you should provide a link
 * using this function.
 * @param string $domain The domain where the page is hosted
 * @param string $appname The name of your application
 */
function recaptcha_get_signup_url ($domain = null, $appname = null) {
    return "https://www.google.com/recaptcha/admin/create?" .  _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
}

function _recaptcha_aes_pad($val) {
    $block_size = 16;
    $numpad = $block_size - (strlen ($val) % $block_size);
    return str_pad($val, strlen ($val) + $numpad, chr($numpad));
}

/* Mailhide related code */

function _recaptcha_aes_encrypt($val,$ky) {
    if (! function_exists ("mcrypt_encrypt")) {
        die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
    }
    $mode=MCRYPT_MODE_CBC;   
    $enc=MCRYPT_RIJNDAEL_128;
    $val=_recaptcha_aes_pad($val);
    return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
}


function _recaptcha_mailhide_urlbase64 ($x) {
    return strtr(base64_encode ($x), '+/', '-_');
}

/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
function recaptcha_mailhide_url($pubkey, $privkey, $email) {
    if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
        die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
             "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
    }


    $ky = pack('H*', $privkey);
    $cryptmail = _recaptcha_aes_encrypt ($email, $ky);

    return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
}

/**
 * gets the parts of the email to expose to the user.
 * eg, given johndoe@example,com return ["john", "example.com"].
 * the email is then displayed as john...@example.com
 */
function _recaptcha_mailhide_email_parts ($email) {
    $arr = preg_split("/@/", $email );

    if (strlen ($arr[0]) <= 4) {
        $arr[0] = substr ($arr[0], 0, 1);
    } else if (strlen ($arr[0]) <= 6) {
        $arr[0] = substr ($arr[0], 0, 3);
    } else {
        $arr[0] = substr ($arr[0], 0, 4);
    }
    return $arr;
}

/**
 * Gets html to display an email address given a public an private key.
 * to get a key, go to:
 *
 * http://www.google.com/recaptcha/mailhide/apikey
 */
function recaptcha_mailhide_html($pubkey, $privkey, $email) {
    $emailparts = _recaptcha_mailhide_email_parts ($email);
    $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);

    return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
        "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);

}


?>
0

Changed it? Why? The ReCaptcha library file is meant to be used as is.

I'd suggest downloading a fresh copy and not changing it.

0

I mean the file name suppose to be recaptchalib.php not recaptcha.php. I did not change the content.

Edited by davy_yg

1

I believe the problem is on line #107.

The EOD; must have no white space before it whatsoever. In the code you posted, it appears to be preceeded by a tab.

The code editor doesn't seem to be able to handle code containing textareas, so I have attached the source code for the form I posted previously.

Attachments
0

Thanks I am almost there. The form works before I merge it with my page.

After I merge it I have this error:

Could not open socket

Click Here

You can try it yourself.

konsultasi-konsumen.php

<?php

// FORM VALIDATION AND RECAPTCHA SETTING

// Include ReCaptcha and define keys
require_once('recaptchalib.php');
define('RECAPTCHA_PUBLIC', '6Lc1ntQSAAAAAAxrl-iJui8kXgFAUemdhcbV38hl');
define('RECAPTCHA_PRIVATE', '6Lc1ntQSAAAAAOIcduLKmNVXGTz1ddZ6AZyzGfl6');

// Define notification recipient
define('NOTIFICATION_RECIPIENT', 'davy_yg@yahoo.com');

// Define data and error arrays
$data = array('name' => '', 'email' => '', 'phone' => '', 'message' => '');
$errors = array();
$error = '';

// Check if form submitted
if($_POST) {
    // Prepare form data and captcha 
    $data = array_merge($data, $_POST['form']);
    $captcha = recaptcha_check_answer(RECAPTCHA_PRIVATE, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);

    // Validate name
    if(strlen(trim($data['name'])) == 0)
        $errors['name'] = 'Name is mandatory';

    // Validate email
    if(strlen(trim($data['email'])) == 0)
        $errors['email'] = 'Email is mandatory';
    elseif(! filter_var($data['email'], FILTER_VALIDATE_EMAIL))
        $errors['email'] = 'Email is not valid';

    // Validate phone
    if(strlen(trim($data['phone'])) == 0)
        $errors['phone'] = 'Phone is mandatory';

    // Validate message
    if(strlen(trim($data['message'])) == 0)
        $errors['message'] = 'Message is mandatory';

    // Validate captcha
    if(! $captcha->is_valid)
        $errors['captcha'] = 'Captcha is incorrect';

    // Send email and redirect user if no form errors
    if(! $errors) {
        if(send_notification($data))
            header('Location: thank-you.php');
        else
            $error = 'An unexpected error occurred. Please try again.';
    }
}
?>

<div id="form">
        <form method="post" action="konsultasi-konsumen.php">
            <?php if($error): ?>
                <h3><?php echo $error; ?></h3>
            <?php endif; ?>

            <table border="0">
                <tr align="left">
                    <th><div class="form-row">
                        <label for="name">Name</label><br /></th>
                    <th><input id="name" type="text" name="form[name]" value="<?php echo $data['name']; ?>" />

                        <?php if(isset($errors['name'])): ?>
                            <span class="form-error"><?php echo $errors['name']; ?></span>
                            <?php endif; ?>
                    </div></th>
                </tr>                        

                <tr align="left">
                    <th><div class="form-row">            
                            <label for="email">Email</label><br /></th>
                    <th><input id="email" type="text" name="form[email]" value="<?php echo $data['email']; ?>" />

                        <?php if(isset($errors['email'])): ?>
                            <span class="form-error"><?php echo $errors['email']; ?></span>
                            <?php endif; ?>
                    </div></th>
                </tr>

                <tr align="left">
                    <th><div class="form-row">
                            <label for="name">Phone</label><br /></th>
                    <th><input id="name" type="text" name="form[name]" value="<?php echo $data['phone']; ?>" />

                        <?php if(isset($errors['phone'])): ?>
                            <span class="form-error"><?php echo $errors['phone']; ?></span>
                            <?php endif; ?>
                    </div></th>
                </tr>

                <tr align="left">
                    <th><div class="form-row">
                            <label for="message">Message</label><br /></th>
                    <th><textarea id="message" name="form[message]"><?php echo $data['message']; ?></textarea>

                <?php if(isset($errors['message'])): ?>
                    <span class="form-error"><?php echo $errors['message']; ?></span>
                <?php endif; ?>
                    </div></th>
                </tr>

                <tr><th><br></th></tr>

                <tr align="left">
                    <th colspan="2"><div class="form-row">
                <?php echo recaptcha_get_html(RECAPTCHA_PUBLIC); ?>

                <?php if(isset($errors['captcha'])): ?>
                    <span class="form-error"><?php echo $errors['captcha']; ?></span>
                <?php endif; ?>
                </div></tr>

                <tr align="left">
                    <th colspan="2"><div class="form-row">
                <input type="submit" value="Submit" />
                </div></th></tr>

                </table>
        </form>
</div>

Edited by davy_yg

0

I can see the error.

After correctly submitting the form, do you receive the email notification and the error, or just the error?

It could be an issue with ReCaptcha not being accessible when it comes time to validate the captcha.

Have you created the thank-you.php page on line 49?

0

just the error.

I just add: 'captcha' => '' to the arrays. the same error still appears. what else should I edit?

Not yet, I will soon.

Edited by davy_yg

0

You say it worked before you integrated it into your page. Is the script still hosted on the same server, or is it a different server?

The error is occuring because ReCaptcha is unable to open a connection in order to verify the response - look at the source code in recaptchalib.php

0

I don't really understand the source code in recaptchalib.php - it's complicated.

it still hosted on the same server.

0

I have no explanation as to why it would suddenly fail.

If the script is hosted on the same server, that would suggest it's not a server config issue and rather that it's an external issue, which may or may not be temporary.

Open your recaptchalib.php file and replace line 81 with:

die ("Could not open socket - {$errno}: {$errstr}");

See if that gives you more information.

0

Hi,

My webhosting does not block the google IP address. They have tried to disable the firewall and the same result still occured.

Is there any other way that may cause the connection time out?

Thanks.

0

This error:

Could not open socket

appears on the form that you have me when I upload it online.

0

What does this show when you run it locally and on your live server?

$socket = fsockopen('www.google.com', 80, $errno, $errstr, 10);
var_dump($socket, $errno, $errstr);

The fsockopen request only appears within the Google ReCaptcha script. If it's failing for some unknown reason, you may be better asking these questions in their support forum.

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.