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.

This tab offers two resources for controlling the PDF output:

  • $args array : contains information regarding the submission & form.
  • $info variable : contains layout, filename and other pdf-related info.

You can view the structure of these two resources by using the following line:

      var_dump($args); die();


      var_dump($info); die();
  • 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.

  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 = JFactory::getDbo();

  // Prepare query to get all fields
  $query = $db->getQuery(true)
    ->from($db->qn('#__rsform_properties', 'p'))
    ->leftJoin($db->qn('#__rsform_components', 'c').' ON ('.$db->qn('c.ComponentId').' = '.$db->qn('p.ComponentId').')')

  // 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>';

12 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