Export attachments easily

Status
Not open for further replies.
Yes, it works ! But my Javascript rules are not take into account (hidden fields appear).

No problem when I use the print button.

Can I improve this on the PDF button ?
 
Nope. the print button works because it's being rendered in the browser, which is where JavaScript runs. PDF is rendered on the server, where there is no JavaScript.

The only way to achieve it would be to use a custom template for the PDF view, and duplicate your JavaScript logic in PHP.

-- hugh
 
Hummm okay, not easy...

Yes I am interested (I have already customized, a little bit, the template of list PDF export, but without PHP code), have you just an example please ? Not any particular about this kind of changes ?
 
In your tempate's default_group.php, where it does the foreach loop around $this->elements,

Code:
foreach ($this->elements as $element) :
    $this->element = $element;

... you would need to check to see if $element (the one being processed) is one you may need to hide, and if so, check the value of the element which "controls" it. So, if for instance, you need to hide yourtable___foo if yourtable___bar has the value 2, then you would ...

Code:
   if ($element->id == 'yourtable___foo_ro' && $this->elements['yourtable___bar'] == '2') {
      continue; // skip this, move on to next element
   }

Note the _ro on the end of the element id, which we add to element id's in a read only context.

-- hugh
 
Hi, thank you for details.

I try to do this, but I do not understand where I have to put exactly my code.

However, to begin, I would do something very simple : to hide a field if this field has the value 0.

So, in the default_group.php, I have tried this for example (just adding the "PERSONAL CHANGES") :

Code:
...
<?php
$rowStarted = false;

foreach ($this->elements as $element) :
    $this->element = $element;
   
    $this->element->single = $single = $element->startRow && $element->endRow;

    if ($single)
    {
        $this->element->containerClass = str_replace('fabrikElementContainer', '', $this->element->containerClass);
    }

    $element->fullWidth = $element->span == 'span12' || $element->span == '';
    $style = $element->hidden ? 'style="display:none"' : '';

    if ($element->startRow) :
   
    // PERSONAL CHANGES
    if ($element->id == 'projets___budget_bmp_ro' && $this->elements['projets___budget_bmp'] == '0') {
        continue;
    }
    // END OF PERSONAL CHANGES
?>
...

I have tried with or without the "..._ro" ; I have tried to put my changes elsewhere in this php tag... no success...

Can you help me ?

Thanks !!!
 
No, you would need to put the skip checking immediately after those first two lines I quoted, at the top of the foreach loop.

-- hugh
 
Yes, I have already tried, but without success.
Like this :
Code:
<?php
$rowStarted = false;

foreach ($this->elements as $element) :
    $this->element = $element;

    // PERSONAL CHANGES
    if ($element->id == 'projets___budget_bmp_ro' && $this->elements['projets___budget_bmp'] == '0') {
        continue;
    }
    // END OF PERSONAL CHANGES
  
    $this->element->single = $single = $element->startRow && $element->endRow;

    if ($single)
    {
        $this->element->containerClass = str_replace('fabrikElementContainer', '', $this->element->containerClass);
    }

    $element->fullWidth = $element->span == 'span12' || $element->span == '';
    $style = $element->hidden ? 'style="display:none"' : '';

    if ($element->startRow) :
?>
 
Last edited:
Double check the data you are expecting, for both the id and the value. So under // PERSONAL CHANGES add:

Code:
echo 'element id = ' . $element->id  . 'value = ' . $this->elements['projets___budget_bmp'] . '<br>';

this will print out the two variables you are checking. one line per element.
Check that you really do have 'projets___budget_bmp_ro' and '0' on the same line.
 
Hummm, it is very strange :
With this last change, I have, for every elements in my PDF, this line:

element id = projets___name_user_submit_rovalue =

With, each time, the name of the element ("projet___...").
Like in the attached file.

What do you think about ?
 

Attachments

  • Projet à valider-555 (1).pdf
    54.6 KB · Views: 213
Ah ok I see :)

As we are in the group template, '$this' refers to the group. Thus, in this context $this->elements only refers to the current group's element and is keyed on the element short name e.g. "budget_bmp"

I'm not sure if your form has only one group. If it does then its safe to do:

Code:
if ($element->id == 'projets___budget_bmp_ro' && $this->elements['budget_bmp']->value == '0') {

If you have more than one group it would be advisable to do this instead:

Code:
if ($element->id == 'projets___budget_bmp_ro' && $this->groups['projets']->elements['budget_bmp']->value == '0') {
 
Aaaaaaaaa !!! Thank you, it starts to look like what I want !

A peculiarity : I have many groups in this form, but it is just your first proposal which runs.

So, I have now many questions to do others things in my PDF exports, but I do not know if you prefer I open other ticket or not ? Say me.

Examples :

- I would also to hide all a group if a element of this group have a special value.

- In some elements of my form, I have pictures in the label, and this pictures do not display correctly in the PDF (Black and white, and not the good picture in the right element).
To solve this, I would do something very simple : to hide all pictures in my PDF exports. Indeed, pictures are useless in my PDF exports.

Thanks for all !!! ;)
 
Last edited:
Hello

Sorry for all my questions... L will try to be more clear, with just my main problem.

Grace to you, I can now to hide fields (integer), if equal to 0 fro example, like this:
Code:
if ($element->id == 'table___champ1_ro' && $this->elements['champ1']->value == '0') {continue;}

But I would also to hide other fields if one (text) is equal to a string (like 'not review' for example), but hidding all the group of this fields (I have some text in my group intro, group title, which would be hidden also).

I have try a lot of combinaison from the code above, but without success...

Thanks in advance for all councils !
 
do you mean you want to remove a group from the form based on another fields value?
The simplest way would be to do this with the element's js events, no custom coding required, but I guess that isn't what you want as you are already doing custom template work to remove elements from the form?

In that case in your form's default.php template:

where you have:

PHP:
foreach ($this->groups as $group) :

replace with :

PHP:
foreach ($this->groups as $group) :
  if ($group->id = 111 && $this->groups['projets']->elements['budget_bmp']->value == 'some text') :
    continue;
  endif;

That says if the group id is 111 and the element's value is 'some text', skip rendering this group.
 
Thanks but no, it does not work...

I know JS event, I use it, with success on form.

But here, I want control displaying of fields in PDF export, so I guess I have to change the detail's default.php template. So, I have try this for example :
Code:
<?php
endif;

echo $form->intro;
echo '<div class="fabrikForm fabrikDetails" id="' . $form->formid . '">';
echo $this->plugintop;
echo $this->loadTemplate('buttons');
echo $this->loadTemplate('relateddata');

foreach ($this->groups as $group) :

    // PERSONAL CHANGES
    if ($group->id = 282 && $this->groups['projets']->elements['commentaires_bmp']->value == 'Projet non-examin?') :
    continue;
      endif;
    // END OF PERSONAL CHANGES

    $this->group = $group;
    ?>

But it does not change anythings...
 
The first and simplest thing I can see is that the inital code I wrote has a typo in it. The sing;le "=" should of course be a double "==" as we are doing a comparison and not an assignement:

PHP:
if($group->id== 111 && $this->groups['projets']->elements['budget_bmp']->value=='some text'):
   continue;
endif;

Otherwise, a couple of thoughts - ensure you have PHP error reporting turn on 'developer' when you test this - it might pick up errors in your PHP

Then echo out the things you are testing - to work out what those values are.
 
Hi

Thanks, I have tested, but no, it does not work, sad...

And I do not know how do an echo on my groups..., I have tried but without success...

Please could you look up on my website ? I am really blocked, I have tried a lot of kinds on my code, but I do not understand, sorry....

:(
 
Sure, can you fill in the site's ftp details, and tell me which list you are working on?

Merci!
Rob
 
Hi

OK, it is done for ftp's details.

Please, for clarity, connect you on the front with another ID, for be a simple user on the front, and a superuser on the end.
Use the ID "fabrik-user" on the front, same password like your super-user.

- On the front, the list wich I work is here: http://driihm.fr/validation-des-projets

- On the back, the name of the list is "Validation des projets de recherche" (ID 47) ; the name of the form is "Projet ? valider" (41)

- On the form, I have settled the detail and PDF templates with my own template called "projets_validation", a copy of the bootstrap template.

Thank you in advance, ask me for all details.

See you
 
Hi you weren't far off, it was just the name of your group that was out, this is the code that works:

PHP:
if ((int) $group->id === 282 && $this->groups['PR ? valider (Choix BMP 2)']->elements['commentaires_bmp']->value === 'Projet non-examin?') :
   continue;
endif;

I've updated your projets_validation_form form template with this code.

For info I went about debugging this by first checking what keys were available in $this->groups :

PHP:
echo "<pre>";print_r(array_keys($this->groups));echo "</pre>";

that showed me there was no key 'projects'

Then in the admin I looked at what group the element 'commentaires_bmp' belonged to. I saw it was 'PR ? valider (Choix BMP 2)' and that group existed in $this->groups array keys. So I replaced that.

I also prefer to compare with === rather than ==. This checks both the variable type as well as its value. So I check that the integer of the group id is 282 ((int) $group->id === 282)

Finally to check that the group was being skipped I temporarily set the code to:

PHP:
if ((int) $group->id === 282 && $this->groups['PR ? valider (Choix BMP 2)']->elements['commentaires_bmp']->value === 'Projet non-examin?') :
  echo "<h1>Ignore this group</h1>";
  continue;
endif;

I then refreshed the page and checked that 'Ignore this group' was written as a heading in the page. Once I had checked that I removed the echo statement.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top