Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2012-04-23 17:26:54
- Freeant
- Member
- Registered: 2012-04-16
- Posts: 36
Empty comment
If I leave the field clean (name, email, www, comment), and click Preview, comment as it is added, but not saved.
Can I make it so – if at least one field is empty (except for www), Preview button mustn’t work. Or do something else to make it realize.
Last edited by Freeant (2012-04-24 20:54:19)
Offline
Re: Empty comment
If you use jQuery, probably the simplest way is to append
<script type="text/javascript">
$(function () {
$("#name,#email,#message").attr("required","required");
});
</script>
at the end of the comment_form
.
Offline
#3 2012-04-25 10:44:49
- Freeant
- Member
- Registered: 2012-04-16
- Posts: 36
Re: Empty comment
thx etc,
but
And how you can add your hint. For each field, different
required: "Please enter your name"
required: "Please enter your email address"
required: "Please enter a message"
Offline
Re: Empty comment
<script type="text/javascript">
$(function () {
$("#name").attr({ required: "required", placeholder: "Please enter your name" });
//and so on for #email, etc
});
</script>
Offline
#5 2012-04-25 11:55:01
- Freeant
- Member
- Registered: 2012-04-16
- Posts: 36
Re: Empty comment
<script type="text/javascript">
$(function () {
$("#name").attr({ required: "Please enter your name", placeholder: "Please enter your name" });
...
And how to change the inscription (hint)?
Please fill out this field.
Offline
Re: Empty comment
If I get your question right,
<script type="text/javascript">
$(function () {
$("#name").attr({ required: "required", placeholder: "Please enter your name", title:"Please fill out this field" });
$("#email").attr({ type: "email", required: "required", placeholder: "Please enter your email address", title:"Please fill out this field" });
$("#message").attr({ required: "required", placeholder: "Please enter a message", title:"Please fill out this field" });
});
</script>
should work, except with Internet Explorer until the next version (10).
Offline
#7 2012-04-25 13:50:51
- Freeant
- Member
- Registered: 2012-04-16
- Posts: 36
Re: Empty comment
Ok, thx,
How do I remove this text: Please fill out this field.
Last edited by Freeant (2012-04-25 13:55:36)
Offline
Re: Empty comment
I think those messages are produced by the browser you are using and can only be overridden with proprietary browser-specific directives. See x-moz-errormessage and here for further ideas. These messages are of course meant to help.
If you want to stop the box appearing, you need to remove your required attribute, but that of course means losing that facility.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Empty comment
I see. You can try something like this:
<style>.inputError{background:yellow;}</style>
<script>
$(function() {
$("#name").attr({ placeholder: "Please enter your name" });
$("#email").attr({ type: "email", placeholder: "Please enter your email address" });
$("#message").attr({ placeholder: "Please enter a message" });
//
$('form#txpCommentInputForm').submit(function() {
var inputError = false;
$('#name,#email,#message').each(function() {
if(jQuery.trim($(this).val()) == '') {
inputError = true;
$(this).addClass('inputError');
}
});
return !inputError;
});
});
</script>
Last edited by etc (2012-04-25 15:29:59)
Offline
Re: Empty comment
And as jakob writes, if you just want to change the hint:
<script type="text/javascript">
$(function () {
$("#name").attr({ required: "required", placeholder: "Please enter your name" }).attr( "x-moz-errormessage","Go back, nobody!");//Mozilla
...
});
</script>
Offline
Re: Empty comment
Alternatively, you could do it server-side with etc_dom_query. Replace <txp:comment_name_input />
by
<txp:etc_dom_query html='<txp:comment_name_input />' replace="//input@@required=required@x-moz-errormessage=Go back, nobody!" />
in <txp:comment_form />
Offline
#12 2012-04-26 10:46:09
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: Empty comment
etc wrote:
Alternatively, you could do it server-side with etc_dom_query.
Oh dang, I’m only beginning to sense how useful this plugin might be!
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline