Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-01-24 11:17:42

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Adding a class to the comments input form itself

Is there a way to add a class to the <form> tag that is output by comments_form? I know I can add a class to the wraptag, but I’m talking about the <form> tag itself.

I have tried to create my own <form> tags to do this (I can get the action url from looking at the default one) but then any comments input tags don’t parse – I get an error for each one. Before I go down the track of manually creating the whole form (ie. including the input tags), I was just wondering if there is something I’m missing.

Can we add a class in this way using the built-in tags?

Offline

#2 2014-01-24 11:50:40

trenc
Plugin Author
From: Malmö
Registered: 2008-02-27
Posts: 572
Website GitHub

Re: Adding a class to the comments input form itself

Hi,

I think it’s not possible. Why do you want to do this?
It’s not neccessary for CSS or a JavaScript to must have a class attribute applied to this form.

What do you want to achieve with this class? Maybe there is a solution despite the class issue.

Offline

#3 2014-01-24 11:59:21

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Adding a class to the comments input form itself

aslsw66 wrote #278427:

Can we add a class in this way using the built-in tags?

No, but if you use jQuery (or etc_query server-side), you can:

<script>
$(function () {
	$("#txpCommentInputForm").addClass("myClass");
});
</script>

Offline

#4 2014-01-24 12:00:59

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Adding a class to the comments input form itself

Thanks for this – I’ll try it out tonight.

I’m such an old-fashioned HTML dude that I forget how easy it is to do this stuff in javascript. Mind you, I’ve always felt that there was something faintly suspicious about scripts working away behind the scenes where I can’t see them!

Offline

#5 2014-01-24 12:36:10

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Adding a class to the comments input form itself

aslsw66 wrote #278430:

I’m such an old-fashioned HTML dude that I forget how easy it is to do this stuff in javascript. Mind you, I’ve always felt that there was something faintly suspicious about scripts working away behind the scenes where I can’t see them!

You are not alone, we are about 2% to disable js while browsing. In case you care about these 2% (or don’t want to load jQuery), replace <txp:comments_form /> with

<txp:etc_query data='<txp:comments_form />'
	replace="id('txpCommentInputForm')@@class=myClass" />

Offline

#6 2014-01-24 14:17:56

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Adding a class to the comments input form itself

aslsw66 wrote #278427:

Can we add a class in this way using the built-in tags?

I will readily +1 etc’s suggestions. You could also use rah_replace (untested):

<txp:rah_replace from="<form" to='<form class="classname"'>
<txp:comments_form />
</txp:rah_replace>

I don’t recall if comments_form has an in-built class – I don’t think it does – but it’s worth a shot.

Last edited by gaekwad (2014-01-24 14:18:05)

Offline

#7 2014-01-24 14:24:45

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Adding a class to the comments input form itself

Thanks for all three suggestions. I prefer either of the two non-JS dependent solutions, only because they are 100% safe.

I know that comments_form doesn’t pass a class directly to the form, because I checked out the coding – it will only pass it to a wraptag if one exists.

I’ll be testing the other two solutions later on. I think etc_query looks harder, but will ultimately be more rewarding in terms of what it can do.

Offline

#8 2014-01-24 14:26:12

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Adding a class to the comments input form itself

aslsw66 wrote #278441:

I think etc_query looks harder, but will ultimately be more rewarding in terms of what it can do.

etc_query makes you 27% more attractive, too.

Offline

Board footer

Powered by FluxBB