Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Control Permissions


Reply


5 Posts   811 Views

Avatar
cumquat

Community Member, 198 Posts

24 February 2011 at 2:57am

Edited: 24/02/2011 3:04am

Ok i'm sure this is simple, my head is fried so please be gentle. All i want to do is if a user is in group x then show a form/item on a page as well as the rest of the content if they aren't then just the content gets shown. Seems simple enough and probably is, i just don't seem to be able to get it to work. I'm using 2.4.5 and the code i'm using is below, the form is $UploadForm.

Cheers

Mick

<div class="typography">
   <% if Menu(2) %>
      <% include SideBar %>
      <div id="Content">
   <% end_if %>
      <% if Level(2) %>
          <% include BreadCrumbs %>
      <% end_if %>
         $Content
            <% control CurrentMember %>
               <% if inGroup(3) %>
                  $UploadForm
               <% end_if %>
            <% end_control %>   
            <table id="Filelist">
         <thead>
      <tr>
      <th>File</th>
      <th>Last Updated</th>
   </tr>
         </thead>
                  <% control FilesInFolder(Uploads/Secure/SOP) %>
         <tbody>
      <tr >
   <td><a href="$URL">$Name</a></td>
   <td>$LastEdited</td>
</tr>
          <% end_control %>
      </tbody>
      </table>
   <% if Menu(2) %>
      </div>
   <% end_if %>
</div>

Avatar
martimiz

Forum Moderator, 1132 Posts

24 February 2011 at 9:33am

Looks like you're doing it right: the code-snippet below should work - that is: if you are currently logged on to the group that has ID = 3, and if $UploadForm does in fact shows a form, and if the template was flushed after adding the code (tested it just now in 2.4.5):

<% control CurrentMember %>
   <% if inGroup(3) %>
      $UploadForm
   <% end_if %>
<% end_control %>

Maybe test this by adding a bit of text, like

   <% if inGroup(3) %>   
      Show upload form: <br />
      $UploadForm
   ...

Avatar
cumquat

Community Member, 198 Posts

24 February 2011 at 9:18pm

Edited: 24/02/2011 10:16pm

Thanks for the response, the form is there when i don't have the control in place but the moment i add the control it refuses to appear, i added the snippet and that shows so obviously the code was right it's just something to do with the form not wanting to appear when in that control. The form is shown below, all i want is to have a file upload on a page. Sorry missed a bit out of the code. I'm sure it has to be to do with the form even though it works with out the control, the form code is 'adapted' from one somewhere else and only seems to work with that blank fieldset in which leads me to believe its probably wrong.

public function UploadForm() {
      
      $form = new Form (
         $this,
         "UploadForm",
         new FieldSet (
            $Attachment = new FileUploadField('Attachment','Upload a PDF or Doc file')
         )
new FieldSet ( )
);
      $Attachment->setFileTypes(array(
         'pdf',
         'doc'
      ));
      $Attachment->setUploadFolder("Uploads/Secure/SOP");
      return $form;
      }

Avatar
martimiz

Forum Moderator, 1132 Posts

25 February 2011 at 12:19am

Ah... I'm thinking again!

$UploadForm wouldn't work within the control, since UploadForm() is a Page method, not a Member method. So within the control you should probably use something like $Top.UploadForm...

Avatar
cumquat

Community Member, 198 Posts

25 February 2011 at 12:46am

You sir, are a star!!!!

Man i was going mental here trying to find a way/hack to get this to work.

Thanks again

Mick