Can’t validate input
-
WordPress 4.9.4 running Mindstream Child Theme theme.
Running PHP version: 5.6.31-4+wpengine10Hi – I’m demoing the free version of Mail Chimp for WordPress…hoping to get this working and then buy the full version.
there’s basically one thing I need it to do: collect emails and validate a predetermined code that the user needs to know in order to get a download.
I have added your validation code to functions.php and changed the necessary values to match my needs:
if( $_POST[‘CODE’] !== ‘GIMMEPOWER’ ) {
(full code at bottom of post)
With the code in functions.php, the validation code rejects all input whether or not it is correct.
I have also tried moving the code to the plugin editor you suggest (My Custom Functions), and also to the Body Scripts field of a page that references the shortcode for your form. In both of these cases, the validation code does nothing and allows all input.
—CODE:
/**
* Performs additional form validation on MailChimp for WP forms*
* @return array An array of error codes.
*/
function myprefix_validate_mc4wp_form( $errors ) {
// perform validation here
if( $_POST[‘CODE’] !== ‘GIMMEPOWER’ ) {
$errors[] = ‘incorrect_value’;
}
return $errors;
}
add_filter( ‘mc4wp_form_errors’, ‘myprefix_validate_mc4wp_form’ );
/**
* Registers an additional MailChimp for WP error message
*
* @return array Array of messages
*/
function myprefix_add_mc4wp_error_message( $messages ) {
$messages[‘incorrect_value’] = ‘Please enter the correct value.’;
return $messages;
}
add_filter( ‘mc4wp_form_messages’, ‘myprefix_add_mc4wp_error_message’ );
The page I need help with: [log in to see the link]
The topic ‘Can’t validate input’ is closed to new replies.