Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Highlight error fields in forms
Hi there,
I want to go a step further than the standard error message that appears when comment forms are not completed properly, and actually highlight each and every input field that is incorrect (like if there was actually a <txp:if_comments_error_email> or txp:if_comments_error_name> tag for example). This would be achieved by a combination putting a css class of ‘error’ on a div surrounding the input field and some txp coding.
I’m scratching my head on how to achieve it. I know I can load <txp:error_message> into a <txp:variable> as a value, but can’t work out how to narrow that down to target a specific error (email, name or comment). The standard language file has generic responses to these errors such as ‘Please enter your name.’ and ‘Please enter a comment.’ which I guess could be targeted somehow but that would not be best practice.
Any ideas?
Cheers,
Phil
Offline
Re: Highlight error fields in forms
philwareham wrote:
highlight each and every input field that is incorrect
Incorrect fields have comments_error
class assigned. (Doesn’t “always” apply filters made by plugins, but works with in-build checks).
which I guess could be targeted somehow but that would not be best practice.
You could compare the preview’s output. Comments tags are parsed in the preview, so if you place something like following into your comments preview, it could be used to modify your errors:
<txp:variable name="email" value='<txp:comment_email />' />
And the we can check (later in comment field) if there is an email:
<txp:if_variable name="email" value="">
No email.
</txp:if_variable>
But that doesn’t tell anything if plugins or blaclist are used. But you can also check the error message itself:
<txp:variable name="email" value='<txp:php> echo (str_replace("MyErrorMessageToCheckFor","",comments_error(array())) != comments_error(array())) ? "error" : "noerror"; </txp:php>' />
<txp:variable name="email" value="error">
Error
</txp:variable>
Playing with the comment system isnät that fun or easy. TXP’s comment system isn’t modular like rest of TXP. Remember to not try to call comment form tags as functions, those aren’t what they seem.
Offline
Re: Highlight error fields in forms
Thanks Jukka,
Did not realise that the inputs have a class of comments_error (guess I should check the code better in future). I’ve given up the idea of applying the error class to a div and will just style the comments_error class instead – that’s good enough for my needs.
Cheers,
Phil
Offline
Re: Highlight error fields in forms
Actually it was a good thing you asked ! I am going to apply it to my TXP site too ! Thanks !
اردو میں بھی دستیاب Textpattern آپ کے لیے اب
Offline
Pages: 1