This topic is locked

Hide view link dependant on field value.

5/20/2008 4:11:13 PM
PHPRunner General questions
M
mmponline author

I have a list page with a few fields and then the view link (to view page).
I need the view link only to display when the field: Advertiser = Yes. When the field Advertiser = No, there must be no link (View) displayed.
Please assist.

S
steveh 5/21/2008

Not answering your question, but as an aside you need to add the security to the view page as relying on not showing the link could cause you issues in the future.
Here's a possible answer to your question though, have 2 pages, one visible to advertisers and have security such that they see this page and have access to the view page, and the other identical page but without the view only available to non advertisers?

J
Jane 5/21/2008

Stephan,
here are some tips:

  1. edit view link on the Visual Editor tab in HTML mode:
    {if $row.show_viewlink}

    <a href="...">View</a>

    {/if}


2. check field value in the List page: After record processed event:

if ($data["FieldName"]=="Yes")

$smarty->assign("show_viewlink",1);

else

$smarty->assign("show_viewlink",0);

M
mmponline author 5/21/2008

Jane
I've added the code as indicated with my own fieldname- Advertiser:

if ($data["Advertiser"]=="Yes")

$smarty->assign("show_viewlink",1);

else

$smarty->assign("show_viewlink",0);


I've also added the if statement. The following error as result:
Fatal error: Call to a member function on a non-object in /usr/www/users/finditm/finditmpdb/include/ListingUser_events.php on line 97

I also insured the "Advertiser" is included in the field list, but still the same...

A
alang 5/21/2008

The $smarty variable isn't a parameter in the after record processed event. You will probably need to declare it global before referring to it in your event code.

M
mmponline author 5/22/2008

Sorry for my ignorance, but how would I do that! I'm trying my best to learn, but feels more like a monkey everyday.

J
Jane 5/22/2008

Stephan
sorry for my fault.

Here is the correct code:

if ($data["Advertiser"]=="Yes")

$row["show_viewlink"]=1;

else

$row["show_viewlink"]=0;

M
mmponline author 5/22/2008

Makes me feel better about my own incapabilities when you do get it wrong, although it does not happen often.
Thanks for your excellent service. It's now 100% what I needed.

P
piccirm@wyeth.com 10/2/2008

I've tried to do this on the list page on the edit link but does not work with 5.0

Any hint?

M
mmponline author 10/2/2008

Hopefully Jane or Sergey will have a solution for this, as I have no idea how to change it.
I'm hesitant to convert older projects to V5 now, as this might happen with other custom coding as well...