eZ Community » Forums » Developer » Testing existence of a post/get...
expandshrink

Testing existence of a post/get variable in templates

Testing existence of a post/get variable in templates

Wednesday 18 May 2005 11:08:37 am - 4 replies

How can I test, in templates, the existence of a
get/post variable? Using ezhttp I have the template error:

<i>Unknown post/get variable 'optvar'</i>

As example, if a form field is optional,
when not filled , it doesn't appear in POST , and when I try the template code:

...
{section show=is_set(ezhttp( 'optvar', 'post' ))}
    optvar = {ezhttp( 'optvar', 'post')}<br>
{/section}
...

It works well but it returns also the described template error.

Modified on Wednesday 18 May 2005 11:09:13 am by Roberto Frascarelli

Monday 30 May 2005 10:15:10 am

Hi Roberto,

is_set() can check variable, ezhttp() is a function so this is a reason why is_set() returns template error.

Monday 30 May 2005 10:23:24 am

Roberto,

You can't avoid that template error when using ezhttp. The code for the operator does a $http->has(Post|Get|Session)Variable() and prints the error in the else branch.

Doing an is_set on the result of ezhttp can't aleviate the problem because the error comes from the ezhttp operator itself.

It annoys me too, but it really isn't a problem with your code, nor in eZ publish's code.

Monday 30 May 2005 10:48:58 am

Ok I understand the nature of the error message,
and the bad use of the ezhttp() function in my template code, but there is only one alternative way to test the existence of a variable in post into templates...the definition of a custom template
function...right?

Modified on Monday 30 May 2005 10:57:50 am by Roberto Frascarelli

Friday 08 February 2013 11:08:19 am

For the sake of completeness there is a function in eZ 4.x:

http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-operators/Data-and-information-extraction/ezhttp_hasvariable

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from