Hi everyone,
i need your help, i have chronoform v4 and i would not like to update it ...
In my form in the "Preview" field I entered "Custom Item" which contains:
But it does not work.
Can you help me please?
i need your help, i have chronoform v4 and i would not like to update it ...
In my form in the "Preview" field I entered "Custom Item" which contains:
<script src="https://www.google.com/recaptcha/api.js?hl=it" async defer></script><body><form action="?" method="POST"><div class="g-recaptcha" data-sitekey="MYWEBSITEKEY"></div><br/><b>*Dati obbligatori</b><br/><br/><input name="submit" class="" value="Invia" type="submit" /></form></body></html>And in "Event" in "On Submit" the "Custom server side validation" function which contains:
<?php// Checks if form has been submittedif ($_SERVER['REQUEST_METHOD'] == 'POST') { function post_captcha($user_response) { $fields_string = ''; $fields = array( 'secret' => 'MYSECRETKEY', 'response' => $user_response ); foreach($fields as $key=>$value) $fields_string .= $key . '=' . $value . '&'; $fields_string = rtrim($fields_string, '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify'); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, True); $result = curl_exec($ch); curl_close($ch); return json_decode($result, true); } // Call the function post_captcha $res = post_captcha($_POST['g-recaptcha-response']); if (!$res['success']) { // What happens when the CAPTCHA wasn't checked echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>'; } else { echo 'success'; }}?>And "In case of error" I entered "Event Loop".But it does not work.
Can you help me please?
I have change PHP code in:
// Checks if form has been submittedWhere the modify is:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
function post_captcha($user_response) {
$fields_string = '';
$fields = array(
'secret' => 'MYSECRETKEY',
'response' => $user_response
);
foreach($fields as $key=>$value)
$fields_string .= $key . '=' . $value . '&';
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
// Call the function post_captcha
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
// What happens when the CAPTCHA wasn't checked
return 'fail';
} else {
echo 'success';
}
}
?>
if (!$res['success']) { // What happens when the CAPTCHA wasn't checked return 'fail'; } else { echo 'success'; }But it not work
Now i have change it in:
Thanks
if (!$res['success']) {
// What happens when the CAPTCHA wasn't checked
return false;
} else {
echo 'success';
}And now it works, but i would like to see an error message, how can i do?Thanks
it's difficult to support v4 today, it's better if you install v7 on the same website and build that form there!
but basically, you can echo a styled message HTML!
but basically, you can echo a styled message HTML!
I have solved my problem:
1. In Preview i have add 2 Costum Element, in the first i insert:

3. In the Costum Server Side Validation i have insert the following code:
1. In Preview i have add 2 Costum Element, in the first i insert:
<script>In the Second:
function recaptchaCallback() {
jQuery('#submit').prop('disabled', false);
}
function recaptchaError() {
jQuery('#error').show();
}
</script>
<script src="https://www.google.com/recaptcha/api.js?hl=it" async defer></script>2.In Events i have insert in ON SUBMIT the Costum Server Side Validation, and OnFail the Event Loop
<body>
<form action="?" method="POST">
<div class="g-recaptcha" data-callback="recaptchaCallback" data-error-callback="recaptchaError" data-sitekey="PUBLIC_KEY"></div>
<p id="error" style="color:red; display:none;"><b>Error Message!</b></p>
<br/>
<input id="submit" type="submit" name="submit" class="" value="Invia" disabled>
</form>
</body>
</html>
3. In the Costum Server Side Validation i have insert the following code:
<?phpI hope it will be of help to anyone who is having the same problem as me
// Checks if form has been submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
function post_captcha($user_response) {
$fields_string = '';
$fields = array(
'secret' => 'PRIVATE_KEY',
'response' => $user_response
);
foreach($fields as $key=>$value)
$fields_string .= $key . '=' . $value . '&';
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
// Call the function post_captcha
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
// What happens when the CAPTCHA wasn't checked
return false;
} else {
return true;
}
}
?>
You need to login to be able to post a reply.
