Hi Everyone, Especially those who are more experienced than others.
I have been teaching myself php over the last 18 months and whilst I can do what I think are basic tasks, the more difficult tasks, well, are more difficult and take much longer to complete.
The reason for my post is this. I am trying to design a bespoke WordPress comment form with additional fields. I have had some help, some of it I understand, the other bits, I am looking into.
What I would like to do, is add my own input validation & error messages, but I haven't got the foggiest idea where to start or how to add them to the WP comments php file.
I have created a replica php file with the same variables as the wp comment variables, Author, Email, Url, Comments & added my own two additional fields.
Now the fun begins.
I have the test form validating required input. ie. Name required, Invalid email address etc.
Here is the post vars - in the test comment form
$author = $_POST['author'];
$email = $_POST['email'];
$url = $_POST['url'];
$country = $_POST['country'];
$dialingCode = $_POST['dialingCode'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
Here is how I am checking and displaying validation error messages in the test wp comments form
//author select
if(!$author)
{
$hint = 'author';
registerError( $hint, $hint, $error_title, 'Name is required' );
$b1=false;
}
What I would like to know is, how could I add this type of php to the wp comments form.
I have looked over some fo the code and most of it looks like this...
if ( ( isset( $_POST['phone'] ) ) && ( $_POST['phone'] != '') )
$phone = wp_filter_nohtml_kses($_POST['phone']);
Am I right in saying that I can add the same type of code as above for author,email & url?
And add the above error message as an elseif statement?
I would, and I am sure other would like to know how to our own validation to wp comments.
Hoping someone can take the timeto explain this to me and others who are less expereinced.