Hey everyone, I have a question and I am not sure if it's possible or not to do it with what I'm using. I am using HTML, PHP, JavaScript, and mySQL to make a web page that pulls information from a Database. After that, I want to have a dropdown menu that asks for a specific kind of letter to be made after everything has been done.

So is it possible for me to make a web page that can dynamically create a text document or something similar once I fill in all the fields and then submit it?

I think you are asking if a business type letter can be made this way. Sure. You would probably format the letter in HTML, and then echo it in php so that you can include variables drawn from your database.

Yes, I am thinking of something of the sort.
This is a sample of what I have. I obviously have to make changes such as make the dropdown pull from the database so that it is dynamic and not static. And you said I could format the letter in HTML. So I would create an html document dynamically? I am a little confused on that part.

<!DOCTYPE html>
    <html>
        <script>
            function Clear()
            {    
                document.getElementById("textarea").value= "";
            }
        </script>
        <body>
            <h1>CUSTOMER LETTERS</h1>
            <p>&nbsp &nbsp &nbsp &nbsp &nbsp PTD Ticket #: 
                &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Sales Engineer: 
                &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Letter:</p>
            <form>
                <input type="text" placeholder="Enter ticket number" name="ticketNumber">
                &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp 
                <select type="text" name="engineer">
                    <option value="SeList">Drop down list</option>
                    <option value="person1">person1</option>
                    <option value="person2">person2</option>
                    <option value="person3">person3</option>
                    <option value="person4">person4</option>
                    </select>
                &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp 
                <select type="text" name="letter">
                    <option value="LetterList">Drop down list</option>
                    <option value="greetingDedicated">Sales Greeting Dedicated</option>
                    <option value="greetingCable">Sales Greeting Cable</option>
                    <option value="installSite">Service Installation For Site</option>
                </select>
                <br>
                <br>
                <br>
                <textarea rows="4" cols="100" placeholder="Free form box to enter services or notes" name="comment" id="textarea" form="usrform"></textarea>

                <br><br>
                <button type="submit" value="Submit">Preview letter</button>
                &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
                &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
                <button type="submit" value="Submit">Send letter and update ticket</button>
                &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
                &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
                <button type="refresh" value="Refresh">Cancel</button>

            </form>
        </body>

    </html>
Member Avatar for RudyM

Absolutely. You'd be creating a something like a document factory abstract class, a document class that extends this document factory. In the document class, you will have the universal variables like a company name and address. And finally, a document which extends it to pull the universal variables, run its own query and set more custom variables.

See if this helps: http://www.phptherightway.com/pages/Design-Patterns.html

Yes its surely possible. You can create such documents to be displayed at the end.

Hey Kumar, would you be able to provide any insight or have any links that I can use to help give me examples so that I can follow along?

Member Avatar for RudyM

Perhaps my approach may be complex, but I think it would pave the way for better maintenance when creating or changing documents. So here's another approach:

Have your dropdown menu point to your different documents; so that on submit (or change), you'll be directed to your document page, e.g., greetingDedicated.php.

First, in greetingDedicated.php, you should have a global .css to include in all your documents, to have a consistent properties (e.g., letterhead, margins, etc.)

Also, are you going to query the DB for anything? I assumed this was the case. If so, you would execute the query and use the return values in your HTML (e.g., <?PHP echo $row['MY_COLUMN']; ?>). Otherwise, are you planning on only using the parameters entered in your original page from where you submitted the document request? If so, then you'd include your variables in the HTML as <?PHP echo $_POST['MY_URL_PARAM']; ?> or $_GET depending on your form method.

Hey @RudyM, I am thinking that I only need to use the database for the dropdown menu for the list of people only. So therefore, I don't think I'll need the database for much else. I guess the part I'm struggling with is having a webpage create a document such as a txt file or pdf or something like that.

Also, I have no idea what to do about the ticket number since I need for that to somehow pull information from a ticket number and I have no idea how to do that since I don't have access to that information here and I don't know how I could send an email to it either if that is the case.

So should I simply make 3 other php pages that will be for the 3 different types of letters? I can use the user input for some variables and echo out the rest? I think that might be the easiest thing for me to do. But it won't be very versatile.

Member Avatar for RudyM

Do you need to create a PDF or TXT for this? I used my former approach and the output would be HTML and straight to printing.

Ticket number? Is this something you can obtain from the database?

It seems like creating the three PHP pages may be the approach to take, if you're not expecting too many other documents to create later.

@RudyM I wasn't given a specification on whether the file could be TXT or PDF or something like that. I figured I could make 3 php files where the person could then copy/paste the text in that page and email their client.

And about the ticket number, I guess I don't need to pull the information from the datbase. I just have to email the ticket number so that the ticket's log is updated. So that shouldn't be a problem.

As for Customer name or something for the letter, I guess I'll have to add more text fields so that the user can put in the customer information for the letter since I have no other way of getting the customer's information.

So would I do something like this?

<input type="text" name="whatever"/>

<!- Create Varible name in a php file
    that will reference the input name -->

And then echo out the value of the variable?

Member Avatar for RudyM

As for Customer name or something for the letter, I guess I'll have to add more text fields so that the user can put in the customer information for the letter since I have no other way of getting the customer's information.

I really feel you'd benefit from using a database connection for this project. You can have the user enter a ticket number, from which you can query a database and obtain the customer data.

And that sample code you wrote, what page is it planned for? Will the page where the user selects the document also have the input fields?

@RudyM yes, the sample code was just being used a reference for a variable for the next page. It looks like I'll create 3 php pages that will be using the same things for the most part.

And yes, the Customer would benefit from a database, but I have no means of being able to get that customer information sadly. The only database connection that I'll have is for the dropdown menu for the names so that the person assigned the task will be emailed as well. And when the table for that database changes, the menu will change as well.

@RudyM the letters are not too different from each other minus a few details.

Member Avatar for RudyM

Sounds like an interesting project. Best of luck, I hope you have a good starting point.

@RudyM thanks! I am pretty much starting from scratch due to the privileges I have here and they want me to do things that require more. So I started off creating a database of my own for names, ids, emails, and so forth. I have a page that will update, add, and delete things from that table. This page I'm currently working on is the most painful for me due to my low privileges

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.