Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-06-18 11:23:24

gavnosis
Member
From: Milton Keynes, UK
Registered: 2005-03-12
Posts: 151
Website

Assigning a _class_ to search form

Using the txp tag of <txp:search_input /> generates a form (amongst other things), and I know it is possible to assign an id as per the docs: html_id="id"

Is it possible to give the generated form a class?

Or, should I write the search form long-hand?

Offline

#2 2018-06-18 13:24:02

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,165
Website

Re: Assigning a _class_ to search form

Maybe:

<txp:search_input wraptag="form" class="some_class_name" />

But I would build the whole widget myself. By default, it appears that the tag looks for a form named search_input (I didn’t know that until recently). See here for the form used by the default TXP theme . but you can name the form anything you want.

<txp:search_input form="some_name" />

Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#3 2018-06-18 13:29:18

gavnosis
Member
From: Milton Keynes, UK
Registered: 2005-03-12
Posts: 151
Website

Re: Assigning a _class_ to search form

Thank you phiw13

This is where I really wish the txp ‘forms’ had been called ‘snippets’ or something else
I was actually wondering about the html form which is generated…

Do I have to edit it here?

<form class="my-class" action="<txp:site_url />">
    <input name="q" type="search" />
</form>

Offline

#4 2018-06-18 13:34:50

gavnosis
Member
From: Milton Keynes, UK
Registered: 2005-03-12
Posts: 151
Website

Re: Assigning a _class_ to search form

Your suggestion to add a wrap tag then adds two forms…

<txp:search_input wraptag="form" class="some_class_name" />

And then the generated code is:

<form method="get" action="<txp:site_url />">
<form class="some_class_name">Search<br />
<input name="q" type="search" size="15" required="required" value="" /></form>
</form>

Offline

#5 2018-06-18 13:41:49

gavnosis
Member
From: Milton Keynes, UK
Registered: 2005-03-12
Posts: 151
Website

Re: Assigning a _class_ to search form

Ooops! Answered it myself, and added the class to the customised search_input form :

<form class="some_class_name" action="<txp:site_url />">
<input class="form-control" type="text" name="q" />
</form>

Offline

#6 2018-06-18 13:42:41

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Assigning a _class_ to search form

Similar to your situation. Applied to the search form:

<txp:php>echo preg_replace('/id="YOUR_ID"/','id="YOUR_ID" class="YOUR_CLASS"', parse('<txp:search_input html_id="YOUR_ID" />'));</txp:php>

In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#7 2018-06-18 13:44:33

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Assigning a _class_ to search form

gavnosis wrote #312618:

Ooops! Answered it myself, and added the class to the customised search_input form :

<form class="some_class_name" action="<txp:site_url />">...

Applies the class to the wraptag, not to the form itself.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#8 2018-06-18 13:45:04

gavnosis
Member
From: Milton Keynes, UK
Registered: 2005-03-12
Posts: 151
Website

Re: Assigning a _class_ to search form

One day I’ll learn to think as elegantly as this! Thank you

Offline

#9 2018-06-18 19:12:59

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Assigning a _class_ to search form

Would rah_replace be helpful in this scenario?

Offline

Board footer

Powered by FluxBB