Hyperlink code help, please.

bclayton

New Member
Hello,

I want to convert an ASP application running on a Windows server to a Fabrik list application. Currently, I have an online order status report that contains a hyperlink field with a shipment tracking number. Shipments are via FedEx, UPS, USPS. When the tracking number is clicked, the proper shipper website opens and displays the tracking reults. The URL for tracking is determined by the length of the tracking number. The relevant code (I think) from the .asp file is below:
<%
Dim strURL
dim sTrackNum

sTrackNum = FP_FieldURL(fp_rs,"TrackingNo")
Select Case len(trim(sTrackNum))
Case 11 'Airborne
strURL = "https://track.airborne.com/TrackByNbr.asp?ShipmentNumber=" & sTrackNum
Case 18 'UPS
strURl = "http://wwwapps.ups.com/WebTracking/...peOfInquiryNumber=T&loc=en_US&InquiryNumber1=" & sTrackNum & "&AgreeToTermsAndConditions=yes&track.x=13&track.y=5"
Case 22 'USPS
strURl = "http://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1="& sTrackNum
Case else ' FedEx
strURL = "http://www.fedex.com/Tracking?template_type=plugin&amp;tracknumbers=" & sTrackNum & "&amp;action=track&amp;language=english&amp;cntry_code=us"
End Select
%>

The tracking number element in my Farbik list is named "shiphow" and is now set as a text field with "Guess link" checked. I know that a lot more has to be done, but I am not sure of the best approach for Fabrik to handle this task. Calc element or?? I'm no expert with code, so if you could point me to examples to help with structure, it would be greatly appreciated.

Thank you!
Brooks
 
Yeah, probably a calc, with "Calc on save only" set to "Yes", something like ...

Code:
$url = '';
switch (strlen('{yourtable___shipshow_raw}')) {
    case 0:
        break;
    case 11:
       $url = '<a href="https://track.airborne.com/TrackByNbr.asp?ShipmentNumber={yourtable___shipshow_raw}">Airborne</a>';
        break;
    case 18:
       $url = '<a href="http://wwwapps.ups.com/WebTracking/processInputRequest?HTMLVersion=5.0&sort_by=status&Requester=UPSHome&term_warn=yes&tracknums_displayed=5&TypeOfInquiryNumber=T&loc=en_US&InquiryNumber1={yourtable___shipshow_raw}&AgreeToTermsAndConditions=yes&track.x=13&track.y=5">UPS</a>';
        break;
    case 22:
       $url = '<a href="http://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1={yourtable___shipshow_raw}">USPS</a>';
        break;
    default:
       $url = '<a href="http://www.fedex.com/Tracking?template_type=plugin&tracknumbers={yourtable___shipshow_raw}&action=track&language=english&cntry_code=us"">FedEx</a>';
        break;
}

return $url;

Replace 'yourtable' with your table name (see your element's full name in the back end element list).

-- hugh
 
Hi Hugh,

Thanks so much for your help!

I changed the element to calc and changed the saved setting. I changed the code to reflect my table (orders). When viewed, the tracking number does not show as a hyperlink and nothing happens when clicked. I am attaching the changed code and a screenshot o the backend of the element. Do I need to do something else?

$url = '';
switch (strlen('{orders___shiphow_raw}')) {
case 0:
break;
case 11:
$url = '<a href="https://track.airborne.com/TrackByNbr.asp?ShipmentNumber={orders___shiphow_raw}">Airborne</a>';
break;
case 18:
$url = '<a href=http://wwwapps.ups.com/WebTracking/...peOfInquiryNumber=T&loc=en_US&InquiryNumber1={orders___shiphow_raw}&AgreeToTermsAndConditions=yes&track.x=13&track.y=5"">UPS</a>';
break;
case 22:
$url = '<a href="http://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1={orders___shiphow_raw}">USPS</a>';
break;
default:
$url = '<a href="http://www.fedex.com/Tracking?template_type=plugin&tracknumbers={orders___shiphow_raw}&action=track&language=english&cntry_code=us"">FedEx</a>';
break;
}

return $url;

Brooks
 

Attachments

  • shiphow.png
    shiphow.png
    85.4 KB · Views: 106
Hugh,

Update. I discovered if I leave the Only calc on save setting to No and set Calc on load to Yes, it works! This is in the list view and that is just what I want.

Thank you, again, and Happy New Year!

Brooks
 
No, don't use the same element. If you change your 'shipshow' element to calc, it's going to re-write the value as the link in the database.

Create leave your existing shipshow element as a field, create a new calc element, something like shipshow_link, and use that as the element to display the link.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top