05
Days
23
Hours
59
Minutes
59
Seconds


PHP PDF Pre-Processing Scripts

This tab offers you more control over the layout of the PDF document generated by the new PDF plugin available for RSForm!Pro.

Variable name Type Description
$args array contains information regarding the submission & form.
$info variable contains layout, filename and other pdf-related info.
Examples:
  • If you want only the fields that have been filled in by the user to be contained in the body of the PDF document you will need to add an if clause that will verify if the users submitted a value for a specific field. If the field does not have a value then the placeholder will be removed from the PDF layout.
    $ph='{field-name-here:value}';
    $value_key=array_search($ph,$args['placeholders']);

    if ($args['values'][$value_key]=='')
    $info->useremail_layout = str_replace($ph,'',$info->useremail_layout);
  • If you want to automatically add all the field's placeholders that have a submitted value directly into the PDF's layout(in this case, the PDF is attached to the Admin Email), a script will be required that will dynamically check and add your form components. The script is added in the "Admin Email Pre-processing PHP Script":
    // Get database connector
    $db = Joomla\CMS\Factory::getDbo();

    // Prepare query to get all fields
    $query = $db->getQuery(true)
      ->select($db->qn('p.PropertyValue'))
      ->from($db->qn('#__rsform_properties', 'p'))
      ->leftJoin($db->qn('#__rsform_components', 'c').' ON ('.$db->qn('c.ComponentId').' = '.$db->qn('p.ComponentId').')')
      ->where($db->qn('c.FormId').'='.$db->q($args['form']->FormId))
      ->where($db->qn('p.PropertyName').'='.$db->q('NAME'))
      ->where($db->qn('c.Published').'='.$db->q(1))
      ->order($db->qn('c.Order'));

    // Get all fields
    $fields = $db->setQuery($query)->loadColumn();
    foreach ($fields as $field) {
      // Find the :value placeholder and grab its value
      $position   = array_search('{'.$field.':value}', $args['placeholders']);
      $value    = $position !== false ? $args['values'][$position] : null;

      // Find the :caption placeholder and grab its value
      $position   = array_search('{'.$field.':caption}', $args['placeholders']);
      $caption  = $position !== false ? $args['values'][$position] : null;

      // If we have a value, append it
      if ($value && $caption) {
        $info->{$type.'email_layout'} .= '<p><strong>'.$caption.'</strong>: '.$value.'</p>';
      }
    }

13 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that

You Should Also Read

PDF plugin - tips and tricks HOT

Using the {if} statement with RSForm!Pro PDF plugin HOT

Improving the PDF export for submissions HOT

Save PDF file to folder