Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-12-29 12:58:34

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

Return a message on blank search form submit

Hi everybody,

I’m traying to display a message when the user submit a blank search form [with nothing in it :) ].
I’d traying to use the $q variable but can’t obtain anything. It seems the relevant function preserved a such situation.

Do you have any answer to obtain that kind of rule?

Tks lot by advance.

Regards,


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#2 2007-12-31 05:29:45

obeewan
Archived Plugin Author
From: Stockholm, Sweden
Registered: 2004-08-12
Posts: 319
Website

Re: Return a message on blank search form submit

You might need some txp:php stuff to do it. Something like:

<txp:php>
global $q;
if(isset($q)&&empty($q)){
   # what to do when empty
}else{
  # what to do if not
}
</txp:php>

Bit tired so I could be wrong here but give it a go.


Plugins: ob1_advanced_search 1.032b, ob1_search_score 1.0, ob1_pagination 2.5, ob1_title 4.1, ob1_modified 2.1

“Let your plans be dark and as impenetratable as night, and when you move, fall like a thunderbolt.”
— Sun Tzu

Offline

#3 2007-12-31 09:06:10

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

Re: Return a message on blank search form submit

Hi HenriK.

I had try your PHP code and another one but that’s don’t work at all :(

It’s seems the search function preserves such that kind of situation…

Any others ideas? Even with a core hack cause I need it for a website.

Best regards,


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#4 2007-12-31 09:53:39

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

Re: Return a message on blank search form submit

Or can you make use of -smd_if

EDIT: bugger, doesn’t work. Looks like “?q=” is treated by TXP as a failed search (which technically it is) so it always executes the ‘else’ portion of <txp:if_search>. I think you could, however, put obeewan’s code in the <txp:else /> portion of your if_search tag.

Last edited by Bloke (2007-12-31 11:27:18)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2007-12-31 14:37:27

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Return a message on blank search form submit

I just had a similar situation. While testing a new site, I checked out my search page and see a TXP error:

Tag error: <txp:q/> -> Textpattern Notice: tag is deprecated on line 991

The offending tag is here:

<h2><txp:search_result_count text="search results" />: "<txp:q />"</h2>

Looked through TextBook but I can’t find anything on “txp:q”? Anyone know what the correct tag now is, if q is deprecated?

Offline

#6 2007-12-31 14:40:38

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Return a message on blank search form submit

And on the same topic of errors (without wishing to hijack the thread, but the error message is almost the same), I get this error from the default_error page, when checking if it works:

Notice: tag is deprecated in /users/home/solborg/web/public/textpattern/publish.php on line 991

Which tag?? Its the same publish.php line 991.

Offline

#7 2007-12-31 14:53:47

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Return a message on blank search form submit

Jonathan – for <txp:q /> you should now use <txp:page_url type="q" />.
Without seeing your error page code I can’t say what that is. I presume you are using SVN as these notices are quite new as I recall. Are you using <txp:sitename /> at all?

As far as Textbook is concerned, it isn’t going to be too helpfull putting this stuff in yet as it is for 4.0.6 and most people will be on 4.0.5 or lower. It would be confusing.

Last edited by thebombsite (2007-12-31 14:56:46)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#8 2007-12-31 16:20:50

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Return a message on blank search form submit

thebombsite wrote:

Jonathan – for <txp:q /> you should now use <txp:page_url type="q" />.
Without seeing your error page code I can’t say what that is. I presume you are using SVN as these notices are quite new as I recall. Are you using <txp:sitename /> at all?

Thanks Stuart. I still use your search setup from that tutorial you had ages ago. The one with the search in its own section.

Thanks for the above. In the search page, I changed to <txp:page_url type="q" /> and the deprecated tag error went away. I am using 4.05, so that should be in TextBook.

The second error on the error_default page – yes, I have (had) txp:sitename. I changed that to site_name and the error disappeared. Thanks!

Offline

#9 2007-12-31 17:37:31

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Return a message on blank search form submit

Pat64 wrote:

I’m traying to display a message when the user submit a blank search form [with nothing in it :) ].
I’d traying to use the $q variable but can’t obtain anything. It seems the relevant function preserved a such situation.

This works as it’s based on the url, not the actual TXP-function, but basically it’s the same as the old and deprecated txp:q.

<txp:php> if(gps('q') == '') echo 'Hey, remember to search something!'; </txp:php>

Simple and easy.

PS. I don’t get it why <txp:q /> is deprecated as it holds the same functionality (and code too) as <txp:page_url type="q" />

Cheers!

Last edited by Gocom (2007-12-31 17:41:32)

Offline

#10 2007-12-31 19:58:53

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Return a message on blank search form submit

Jukka – I’m not sure about <txp:q /> but I do know that <txp:sitename /> was never a proper tag. It appears that TXP simply replaced it with $sitename. Whether that’s the same with <txp:q /> for $q and maybe <txp:s /> for $s I’m not sure.

Some of these tag changes are a bit old but the problem hasn’t shown up before as the deprecated notice itself is new and it is a “notice” not an “error”.

Last edited by thebombsite (2007-12-31 20:03:40)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#11 2008-01-01 01:33:31

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Return a message on blank search form submit

s, q, sitename, etc, were never proper tags but a hackish thing that shouldn’t have been done in the first place. page_url has been available for some time, and unlike those other “fake” tags, is document in Textbook.

And yes, it is a notice (“you know, you really shouldn’t be doing that”) as opposed to an error (“ah! you broke it!”), and it wouldn’t show up on your site in Live production mode.

Offline

#12 2008-01-01 15:22:54

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

Re: Return a message on blank search form submit

Yeah. Thanks all!

Gocom said:

This works as it’s based on the url, not the actual TXP-function, but basically it’s the same as the old and deprecated txp:q.
<txp:php> if(gps(‘q’) == ‘’) echo ‘Hey, remember to search something!’; </txp:php>

  • ..and Bloke said:*

Or can you make use of “smd_if”:http://forum.textpattern.com/viewtopic.php?id=25357?
EDIT: bugger, doesn’t work. Looks like “?q=” is treated by TXP as a failed search (which technically it is) so it always executes the ‘else’ portion of <txp:if_search>. I think you could, however, put obeewan’s code in the <txp:else /> portion of your if_search tag.

Based on this tow replies, it works fine.

Thanks again, it’s very usefull.

Have a very, very good new year mates :)

Best regards,

Last edited by Pat64 (2008-01-01 15:23:24)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

Board footer

Powered by FluxBB