An issue with form validation
-
Hello,
I found some issues with form validation (plugin version is 2.6).
1. There is no validation of required fields on the server side. There is only validation for a correct email. So, if JS is turned off a form will be successfully submitted.
2. If email is not valid the error message is not displayed.Why it happens.
The mistake you can find in class.widget.phpFor this type of error you return the string “Please enter a valid email address.” (line #352). As a result
$response[$widgetid]
has a type of string. Then you check a value this way$printresponse = ( self::$response[$widgetid][0] )
(line #276).
But as mentioned above$response[$widgetid]
contains the string not an array. And$response[$widgetid][0]
returns the first letter of the string. In this case it’s “P”. So this condition always returns true and show a green message with the text “l” (the second letter of the real message).How to fix.
First of all you should change the line #352.
From
return __( 'Please enter a valid email address.', 'benchmark-email-lite' );
To
return array( false, __( 'Please enter a valid email address.', 'benchmark-email-lite' ) );
And secondly you should add a strict comparison in line #276.
$printresponse = ( self::$response[$widgetid][0] === true )
—
Regards,
Talgat
- The topic ‘An issue with form validation’ is closed to new replies.