Hi,
I have a captcha problem that gradually drives me crazy. It's a simple script that only works on not-MODX-php-files. As soon as I implement it in MODX I get error messages in different browsers whereas in some browsers it works - but only temporarly. After a few reloads of the page it doesn't work anymore an vice versa.
This is the captcha call within the contact resource:
<section>
<label class="label">Enter characters below:</label>
<label class="input input-captcha">
<img src="assets/plugins/forms/captcha/image.php?[[!generateCaptcha]]" width="100" height="35" alt="Captcha image" />
<input type="text" maxlength="6" name="captcha" id="captcha">
</label>
</section>
A pretty simple snippet ("generateCaptcha"):
All script files are loaded correctly.
The php call on the top of the page:
<?php
// Make the page validate
ini_set('session.use_trans_sid', '0');
// Create a random string, leaving out 'o' to avoid confusion with '0'
$char = strtoupper(substr(str_shuffle('abcdefghjkmnpqrstuvwxyz'), 0, 4));
// Concatenate the random string onto the random numbers
// The font 'Anorexia' doesn't have a character for '8', so the numbers will only go up to 7
// '0' is left out to avoid confusion with 'O'
$str = rand(1, 7) . rand(1, 7) . $char;
// Begin the session
session_start();
// Set the session contents
$_SESSION['captcha_id'] = $str;
?>
I put the code in a snippet and the snippet call in the contact page template: [[!ContactForm]]
The validation script:
<script type="text/javascript">
$(function()
{
// Validation
$("#form").validate(
{
// Rules for form validation
rules:
{
[...]
captcha:
{
required: true,
remote: 'assets/plugins/forms/captcha/process.php'
}
},
// Messages for form validation
messages:
{
[...]
captcha:
{
required: 'Please enter characters',
remote: 'Correct captcha is required'
}
},
// Ajax form submition
submitHandler: function(form)
{
$(form).ajaxSubmit(
{
beforeSend: function()
{
$('#form button[type="submit"]').attr('disabled', true);
},
success: function()
{
$("#form").addClass('submited');
}
});
},
// Do not change code below
errorPlacement: function(error, element)
{
error.insertAfter(element.parent());
}
});
});
</script>
If I use all the codes above in an ordinary standalone php file the captcha works correctly. So it's not a mistake in the code but in the code within MODX. Is something wrong with the snippet or the snippet call? I tried it cached and uncached. The cache of the contact resource is active. I emptied core/cache and the browser caches.
Does anybody have an idea?
Thanks!!!
[ed. note: carlina last edited this post 10 years, 9 months ago.]