Announcement

Collapse
No announcement yet.

Generate personal word document based on form record

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate personal word document based on form record

    Hi,
    I have 3 word documents (sampleA.docx, sampleB.docx, sampleC.docx) with its own content.
    Example: sampleA.docx
    "Hi {name},
    Kindly note that your particular has been created:
    DOB - {dob}
    "
    I created a grid that is linked to a form. My form has the following fields:
    1. name
    2. dob
    3. form_type

    When user select "form_type = A", it will retrieve the sampleA.docx and include the value for the "name" & "dob" into the word document "{name}" & {dob} respectively. The word document can then be downloaded.

    I could not find any solution on the internet, can anyone kindly advise how can I upload the word document to scriptcase and retrieve the respectively document based on the records value?
    ​Thanks.

  • #2
    Not that easy. It depends on the way the document is stored. If it's xml then you can load the complete file into your php, change content, write it and use a blank application to download it. That in general is my approach of templating. Other options to use are rtf. You need a readable format that you can manipulate from within php.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      I tried creating rtf and php file without using scriptcase. I have 3 files (form.php , generate_doc.php, file.rtf).

      form.php​
      <form action="generate_doc,php" method="post">
      FirstName: <input type="text" name="firstname">
      LastName: <input type="text" name="lastname">
      <input type="submit">​
      ​</form>

      ​generate_doc.php
      $firstname = $_POST["firstname"];
      $lastname = $_POST["lastname"];
      .......

      Basically, when my form is submitted, I can download the rtf file directly from the browser with the content filled based on the value keyed in the form. (the coding is done in generate_doc.php)

      ​My question is that instead of manually create a form, I am using scriptcase to create a form. How do I post all the values to the generate_doc.php upon submission of the form?

      Comment


      • #4
        Hi,

        ​To my above question, I tried out a method below but don't know why the variable is not being replace with the value I submitted from the form?

        ​I create a form and a blank application. In my blank application, I have the following coding. In my form, I link to this blank application and I pass the parameter as per attached screenshot.

        $filelocation1 = 'file1.rtf';
        $firstname = [firstname];
        $lastname = [lastname];

        $output = file_get_contents($filelocation1);
        $output = str_replace('[%FIRSTNAME%]', $firstname, $output);
        $output = str_replace('[%LASTNAME%]', $firstname, $output);

        ​I deployed my application and then I put the "file1.rtf" in the same folder as the blank application. In the "file1.rtf", I included [%FIRSTNAME%] and [%LASTNAME%] but the variable was still not replace by the value when I keyed into the form.

        Can someone kindly advise? Thanks.

        Comment

        Working...
        X