Display an Edit Record button\link on details view

bensbenz

New Member
I wanted to add an edit button to the details view on the front-end to make view\editing records a bit more intuitive. As it stands (from what I can tell anyways) if a user needs to view the details of a record and wants to edit that record they have to go back to list view, find the record and then click edit. Since I didn't see any option anywhere to add such a thing I used the PHP plugin on the edit form page to add one. Now when a user goes from list view, and clicks on details they have a button at the top that links them back to the form to edit that record.

To do this edit your form, click on plugins, add using these options:
  • DO: php
  • In: Both
  • On: Edit
  • Process Script: At top of Form (getTopContent)
  • PHP File: - None Selected -
If you just want a simple button that would display for any user you can enter the following in PHP Code:
PHP:
$fullUrl = JURI::getInstance()->toString();
$modUrl = str_replace('details', 'form', $fullUrl, $count);
if ($count > 0) {
    $baseUrl = JURI::base();
    $linkUrl = str_replace($baseUrl, '', $modUrl);
    $link = '<div style="padding:5px 0 5px 30px">Edit this record<a style="padding-left:10px;" title="Edit this record" href="' . $linkUrl . '"><img src="/media/com_fabrik/images/edit.png" alt="Edit"></a></div>';
    return $link;
}else {return;}
If you want to display the button based on a logged in users group (You will have to edit the $allowgroups array with the joomla group ids you wish to allow) use the following code:
PHP:
function array_multineedle_search($arrayNeedles, $haystack){
    foreach($arrayNeedles as $needle){
        if(in_array($needle, $haystack)) return true;
    }
    return false;    
}
$user =& JFactory::getUser();
$usergroups = $user->get('groups');
$allowgroups = array(2,8);
$result = array_multineedle_search($allowgroups, $usergroups);

if($user->guest){
    return;
}elseif($result){
    $fullUrl = JURI::getInstance()->toString();
    $modUrl = str_replace('details', 'form', $fullUrl, $count);
    if ($count > 0) {
    $baseUrl = JURI::base();
    $linkUrl = str_replace($baseUrl, '', $modUrl);
    $link = '<div style="padding:5px 0 5px 30px">Edit this record<a style="padding-left:10px;" title="Edit this record" href="' . $linkUrl . '"><img src="/media/com_fabrik/images/edit.png" alt="Edit"></a></div>';
    return $link;
}else {return;}
}

I am no coding expert, but everything seems to work ok for me. Hopefully it helps someone else as well :).
 

Attachments

  • edit.jpg
    edit.jpg
    16.9 KB · Views: 611
Hi,
I am looking to replicate standard Joomla profile editing functionality. What i mean, user fills in profile data, on menu click he views data (read only) and then clicks on Edit button to edit it. Spent lots of time reading through forums, but no success so far...
Hugh mentioned custom template override, but i couldnt figure out where and how. If there is some tutorial, would be great to see (i know how standard joomla overrides work).

Thanks for support
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top