Save As a Copy Button - IF/ELSE on Form - default.php

nbradshaw

Active Member
Hi -

I am needing to do an if/else statement to show/hide the 'Save As A Copy' button based on a fields value.

I need to do this in the form template - default.php

I have tried this - without success:

PHP:
$status=$this->_row->data->bid_system___user_company;

    if($status===5000){
        echo $form->copyButton;
    }
    else {
        echo "test";
    }
 
Hi, have you tried:

var_dump($status);
exit;

inside the code where you echo the result?

Or ...user_company_raw?
 
Hi there -

Yes, the value is NULL. So I must be using the wrong syntax to get the element value. Any ideas on the correct syntax?
 
Much appreciated troester!

One follow-up question. Would you know how to query the group membership name of the logged in user is - using this same method from the form template?
 
Actually - I got it figure out...

PHP:
//START Check logged in user's group
# get logged in user
$user = JFactory::getUser();

# groups to match
$sourcing_admin_id = 10;
$super_user_id = 8;

# see if the user is in both
if( in_array($sourcing_admin_id, $user->groups ) OR in_array($super_user_id, $user->groups ) ){
        echo $form->submitButton;
  
}else{
        echo $form->copyButton;
}
 
This is my example:
PHP:
//START Check logged in user's group
$user_object = JFactory::getUser();
$current_user_groups = $user_object->groups;

# groups to match
$groups_to_match = array('8','10');

$is_admin = !empty(array_intersect($groups_to_match, $current_user_groups));

# see if the user is admin
if( $is_admin ){
    echo $form->submitButton;
}else{
    echo $form->copyButton;
}
 
Last edited:
thanks startpoing! Do you happen to know how to change the labels of the submit or copy button based on these conditions?
 
Yes - but I want to do it on the template (if possible). So for certain situations I might want to call Save as a copy something else....such as "Submit Change Order"....so it won't be static.
 
Copy this file:
/components/com_fabrik/layouts/fabrik-button.php
in
/templates/your_template/html/layouts/com_fabrik
Then you can change button label, but need to check button id, because this layout override applied to all your forms.
Place this code
PHP:
if($id == 'fabrikSubmit_XXX'){ //XXX - your form id
   $d->label = 'your_new_button_name';
};

after
PHP:
$id = isset($d->id) ? 'id="' . $d->id .'"' : '';
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top