Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Comments: validating input fields: how do I do this?
I’m adding the possibilty comments to my site; it will be moderated comments, and I’m using a popup window for this. It took some time to find out how it works, but it works; except for validating the input fields. I have a simple form, with only three fields: name, email and comment (message)
I got three questions:
1. How do I check whether something is entered in a field, and the field is not empty. This is important for <txp:comment_name_input /> . The Textbook doesn’t mention anything about. I want an error when this field is empty. The same goes for <txp:comment_message_input />.
2. How do I check for a valid email adres in the comment field <txp:comment_email_input />. I discovered that you can fill in any text.
3. When all the three input fields are left empty, the result is that the page is shown where the popup come from, and that is shown in the popup window. But what I want is either closing the popup window or show an error message.
Help is very much appreciated.
Offline
#2 2006-06-19 21:22:08
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Comments: validating input fields: how do I do this?
- Check your admin preferences, under advanced.
Offline
Re: Comments: validating input fields: how do I do this?
I checked this, and both options (for name and email field) are set on required YES. Still no error message when one or both is left empty.
Offline
Re: Comments: validating input fields: how do I do this?
The reason is that you probably removed the txp-tag that is resonsible for displaying the error-messages.
http://textpattern.com/faq/155/where-did-the-error-messages-for-comments-go-how-can-i-style-them
Offline
Re: Comments: validating input fields: how do I do this?
Thanks, this solves the probem partly. When hitting the preview button, the error messages appear.
However:
- it is still possible to enter an email adress that is not valid, eg something without a @.
- after the preview, it is possible to hit the enter button. This button does not display any messages, but then happens what is described under point 3 of my initial posting
Is there a solution for these issues???
Offline
Re: Comments: validating input fields: how do I do this?
I didn’t find the answer with the standard tags of TXP. So I made hack in order to be able to validate the field with the help of Javascript. This has a lot of advantages; it gives me a complete control on the validations. The disadvantage is that a user can disable Javascript; but I think that most users that visit my site have enable Javascript; and for the rest it is too bad.
The hack is as follows: I changed line 133 of ../textpattern/publish/comment.php.
The original line is:
$out = '<form method="post" action="'.$url.'#cpreview" id="txpCommentInputForm">';
I changed this into:
$out = '<form method="post" action="'.$url.'#cpreview" id="txpCommentInputForm" onsubmit="return valideer();">';
The result is that the javascript function valideer is triggered when the preview of submit button is pushed. In this function you can of course put any validation or whatever you want.
Offline