www.webdeveloper.com
Results 1 to 8 of 8

Thread: Looking to create a document generator

  1. #1
    Join Date
    Dec 2009
    Posts
    4

    Looking to create a document generator

    I want to be able to have someone fill out a form with specified information and have a document created from their answers. One example is to have teachers fill in pertinent information and have the program create a letter to the child's parent.

    Is there a program or something that I can get that will do this?

  2. #2
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    Yes.

    PHP with forms.

    I did it with a text rotator to rotate blurbs on some pages... it takes some of the text from the URL, which are search strings.

    You can just use forms to create a form letter easily enough.

    You will need two pages.

    1.) The html page with the form.
    2.) The output page (PHP or whatever) that takes the form data and creates the letter.

    (I'm doing this off the top of my head, so forgive any errors.... shouldn't be any...)

    Form:

    Call this file form.html
    HTML Code:
    <form id="student" name="student" action="letter.php" method="get" >
    <input id="kid" name="kid" value="" type="text">
    </form>
    Letter:
    (save this as letter.php)
    PHP Code:
    <?php

    $who 
    $_REQUEST['kid'];

       if (
    $who == "") {
        
    $student 'Your child';
    } else {

    $student $who;
    }

     echo 
    "Dear Parent,"
     
    echo "<br />"
     
    echo "$student has been a very naughty rascal..."
    ?>
    Last edited by donatello; 12-05-2009 at 06:03 PM.

  3. #3
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    Easier way


    Name this "form.html
    HTML Code:
    <form name="letter" action="letter.php" method="get" >
    Enter Last Name:<input name="last_name" value="" type="text"><BR>
    Enter First Name:<input name="first_name" value="" type="text"><BR>
    <input name="sex" value="son" type="radio"><BR>
    <input name="sex" value="daughter" type="radio"><BR>
    </form>

    Name this: letter.php
    PHP Code:
    <?php
    echo "Dear Mr. ";
    echo 
    $_POST['last'];
    echo 
    ", <br />";
    echo 
    "Your $_POST['sex'], $_POST['first'] has been so poorly behaved in school";
    echo 
    " that we have no recourse but sending your rotten $_POST['sex'] to Federal Prison...";

    ?>
    That is really simplified...

    You can use variables to make it easier... like in my first example...

    Anyway, that's the idea.
    Have fun!

  4. #4
    Join Date
    Dec 2009
    Posts
    4

    submit button?

    Ok, your code makes sense, but don't I need a submit button to get the information from one page to the other?

  5. #5
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    Submit button...

    Ooops.


    I didn't proofread it.

    DUH!
    Of course. A submit button is necessary!


    HTML Code:
    <input value="Generate Letter!" type="submit">
    Add that to the end just before the closing </form> tag.

    Entire code of form page should look like this:

    HTML Code:
    <form name="letter" action="letter.php" method="get" >
    Enter Last Name:<input name="last_name" value="" type="text"><BR>
    Enter First Name:<input name="first_name" value="" type="text"><BR>
    
    <input name="sex" value="son" type="radio"><BR>
    <input name="sex" value="daughter" type="radio"><BR>
    
    <input value="Generate Letter!" type="submit">
    </form>
    Sorry about that! Late night post from Europe...
    Last edited by donatello; 12-06-2009 at 05:03 AM.

  6. #6
    Join Date
    Dec 2009
    Posts
    4

    one more question

    Thank you! This is my first experience with PHP so I am on quite a learning curve... the only thing can't figure out now is how the submit button is supposed to send the information to the letter and have the letter pull up on the same page. Am I missing something? I get a 404page not found when I click submit.

  7. #7
    Join Date
    Dec 2009
    Posts
    4

    nevermind

    I figured it out, thanks so much!!!!

  8. #8
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    That's a very bare-bones general idea of how it works... you can run wild with it now that you've got it working!

    Have fun!


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles