This topic is locked
[SOLVED]

 Custom "View As" Hyperlink

8/25/2011 12:34:13 PM
PHPRunner General questions
mcebula author

Hi all, having links to my view page from outside sources is important to the application I'm building. I was able to change the primary key value of a table so it appears as a link on the list and view pages using the visual editor (hyperlink, URL prefix, display field content = [select primary key field]).
I ran into trouble with compound keys on a child table so I'm backtracking to try to build to learn how to build the hyperlink using the "Custom" type on the "View As" tab. I'm starting with a single field key table since that should be easier, later I can tackle the tougher challenge of combination key made up of 2 fields.
Assume a table called ACTOR has a primary key ACTOR_ID which is a string field.

Here is the code snippet I have in the custom on the ACTOR_ID field on the "View As" tab of the View Page.

$value = "<a href=ACTOR_view.php?editid1=".$data["ACTOR_ID"].">".$data["ACTOR_ID"]."<a/>";


The snippet above is close to working but because ACTOR_ID is a string value and resulting link only grabs only the first word of the key value so for example a record with key = "Benefit Rule Engineer" ...
The correct link should be - http://localhost/bdr/ACTOR_view.php?editid1=Benefit%20Rule%20Engineer

But I'm getting hyperlink is this - http://localhost/bdr/ACTOR_view.php?editid1=Benefit
Did I make a mistake in constructing the link or is there a trick to getting the full key with embedded spaces in between the values?
Thanks.

C
cgphp 8/25/2011
$value = "<a href=\"ACTOR_view.php?editid1=".urlencode($data["ACTOR_ID"])."\">".$data["ACTOR_ID"]."<a/>";
mcebula author 8/25/2011

Thanks Cristian!
Your solution uses a slightly different character in between the words (+ sign instead of %20) but it brings up the page <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=60380&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
New = ACTOR_view.php?editid1=Benefit+Rule+Engineer

View link from magnifying glass icon in list = ACTOR_view.php?editid1=Benefit%20Rule%20Engineer

mcebula author 8/25/2011

Whoops I just noticed something strange. On the view and edit page now, the header at top of page is messed up showing HTML.
Shows like this now:

ACTOR, View record [ ACTOR ID: <a href="ACTOR_view.php?editid1=Benefit+System+Administrator">Benefit System Administrator<a/> ]
Used to show like this:

ACTOR, View record [ ACTOR ID: Benefit System Administrator ]
I marked it as solved but can't unset that <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=60381&image=1&table=forumreplies' class='bbc_emoticon' alt=':unsure:' />

C
cgphp 8/26/2011

Try the rawurlencode function instead.

mcebula author 8/29/2011

Changing to rawurlencode does change to the %20 delimiter but I still have the top of the form messed up on both the edit & view screens showing with HTML embedded. It's both the new custom link and the existing PHPRunner view (from magnifying glass icon)..
Here is my current code snippet:

$value = "<a href=\"ACTOR_view.php?editid1=".rawurlencode($data["ACTOR_ID"])."\">".$data["ACTOR_ID"]."<a/>";


Top of View Page:

ACTOR, View record [ ACTOR ID: <a href="ACTOR_view.php?editid1=Benefit%20Rule%20Engineer">Benefit Rule Engineer<a/> ]
Top of Edit Page:

ACTOR, Edit record [ ACTOR ID: <a href="ACTOR_view.php?editid1=Benefit%20Rule%20Engineer">Benefit Rule Engineer<a/> ]
Do I have something else wrong in the HTML on the code snippet?

C
cgphp 8/29/2011

Ok, I see what you mean. This happens because you have set "View as custom" on the primary id field (ACTOR_ID).
You have to create an alias for the ACTOR_ID in the Query section:

SELECT

ACTOR_ID,

ACTOR_ID as link,

blah

blah

blah

FROM your_table


and set this new alias (link) for the list page as "View as Custom":



$value = "<a href=\"ACTOR_view.php?editid1=".rawurlencode($data["ACTOR_ID"])."\">".$data["ACTOR_ID"]."<a/>";
mcebula author 8/29/2011

Thanks so much Cristian, that was it!