Jump to content

Need to remove input tags but keep the contents


DeX

Recommended Posts

I have a string of html on a page with some <input> tags in it and when the user is done entering information into the boxes, then can hit submit and it fires off the html to a PDF generator. The problem is the generator simply ignores the <input> tags so the whole column is just blank. I need to strip the tags but keep what the user entered in them prior to sending it to the generator.

 

Is there any way I can get rid of the tags surrounding the data in that column? Everything is done in a PHP function in a separate class so it's totally separate from the page the data is displayed on. There is no form being submitted anywhere to run a javascript function on, all data is pulled from the PHP function.

Link to comment
Share on other sites

It's in this basic format, just a regular table:

 

<table>
<thead>
<tr><th></th></tr>
</thead>
<tbody>
<tr>
<td></td>
<td><input type = "text">information</input></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

 

That's basically it with many more rows. I want to strip those input boxes but keep the information inside them. Easy with Javascript but I have no way to call the Javascript function inside a PHP function.

 

 

LONG EXPLANATION:

Here's the long version of what I'm trying to do, don't read this unless you're really interested in what's happening. I got a site where my client can create quotes, they do 100 or more per day. Whenever a quote is confirmed as a sale, they click a button which creates all the purchase orders and also auto-generates the PDF for each one and saves it to the server. That way they can click a button on the page and it sends out all the purchase orders for that quote to order all the materials from each retailer.......the retailer gets an email with a link to the PDF on the server.

I'm calling a PHP function which puts together that specific purchase order including all styling and relevant materials, and stores the HTML into a table so it can be viewed/edited later. I would also like to have the PDF generated at this time but the HTML has the input boxes in it. The reason the input boxes are there is because my client can click any purchase order they want and edit quantities/prices, then resave it which stores the new HTML into the database and creates the PDF again with the new values. Just in case they want an extra couple of pieces of material on that order or the customer is going to be supplying some of it on his own. Then if the customer changes his mind again, my client can go in once again, pull up the purchase order, edit it a second time and resave everything again putting all the HTML into the database again and creating the purchase order for a third time. Now if everything is good they send that purchase order to the retailer to order materials.

Link to comment
Share on other sites

My suggestion would be to use a database table, instead of an HTML table, to store this information on clients and orders.  The concept is similar to a blog:

 

[*]  Create *something* with a standard format

[*]  Save it for recall later

[*]  Can edit at any time

[*]  Display however suits you

 

Why this route?

[*]  Programatically, Your data is more portable and accessible by storing the information inside a database versus storing it in a text-based format. 

[*]  It can be edited by whomever you grant permission

[*]  You can change the output / input format any time and with much more ease

[*]  There's no file conversion flipping-flopping

Link to comment
Share on other sites

All the items are already stored in a database table, that's where they're pulled from to create the purchase order in the first place. But if I have 2 separate functions, one to pull the purchase order with input boxes and another to pull without input boxes, then I have 2 to modify any time a change is made. I want just one function creating the purchase order so modifications are kept to a minimum. Should I reconsider?

Link to comment
Share on other sites

If your information is already in a database, why are you populating the information being sent to your PDF generator formatted as an HTML form?

 

When the quote is confirmed it takes all the materials used to quote that item from the database and creates all the purchase orders, saving each one's HTML layout into the database and also auto creating all the PDF for each one. If they click any of the purchase order links, it'll load up the editable purchase order (HTML from database) on the screen with input boxes for them to edit certain columns if they want. If they do edit, they can save and the new purchase order HTML is sent again to the database and that PDF is generated again with new values.

 

The process is as follow:

- salesman quotes a job, then another, then another, then another

- one of the quotes is confirmed as a sale

- when confirmed, a function is called to generate HTML in a table format which is sent to the PDF generator which creates the purchase order PDF and saves them in a folderon the server. This is done recursively for each purchase order so they're all created and ready to go.

- the purchase orders are not used for anything up to this point and may sit there for a day or two until the guy who orders the buildings looks at it

- guy ordering buildings comes upon this confirmed quote and wants to send out all purchase orders to retailers to order materials

- he clicks the link to view the lumber purchase order so the HTML (same as before) is generated to display on the screen so he can see it including the input boxes.

- he decides an extra 2x4x10 is required for this particular building so he changes the quantity and resaves it.

- this sends the generated HTML once again to the database to be saved and also sends the same HTML to the PDF generator to recreate the new PDF

- the customer calls back and says he'll supply the windows from a local seller

- the guy ordering materials reloads the most recent purchase order and modifies quantities once again, resaving, sending new HTML to the database and recreating the PDF

- most recent PDF is emailed to retailer to order materials

 

The reason the HTML is saved to the database is for ease of editing. In the second last step the guy ordering materials wants to load the purchase order with all the most recent changes, not the original one that gets generated from the original materials list when the quote is first confirmed. So either I create another couple of tables and store every item and every quantity/width/height/price/length again every time they modify a purchase order or I just store the HTML. Then load the HTML so they can edit it again.

 

So basically a PHP function creates the initial purchase order HTML and any subsequent saving is done by just sending the HTML from the screen which is easy. I'm dealing with the inital creation which is done with a PHP function and doesn't have anything to do with what's on the screen.

Link to comment
Share on other sites

The issue I'm trying to understand is why in your review page, your TABLE is being populated with FORM elements.  I understand for ease of access, but that shortcut you're taking is what's causing you this headache.

 

IMO, you have two choices: Option A satisfies the situation, Option B improves it.

 

Option A:

Use regular expressions to remove the form INPUTs when the saved form is submitted to the pdf generator. This will satisfy the issue you're having with the inputs being part of the PDF.

 

Option B:

Recreate the order review page to be a read-only view.  If the employee or customer wishes to update the order, they can click a button / link which will then load the data into FORM elements.  When finished, the read-only view is again loaded and can be used to generate a clean PDF document.

 

Either route you wish to take, there are many here that can help.

Link to comment
Share on other sites

I didn't really know what views were so I looked them up. It seems like a stored SQL query always returning the same rows from the same tables which might help out in some situations but I would need to pull all items with a specific purchase_order_id (belonging to that specific purchase order) and a specific quote_id (belonging to that specific quote). Can I use a view to view a table of items with a certain quote_id and purchase_order_id? There are about 10,000 quotes in the system right now. Each one has about 100 separate pieces of material in its relevant quote-material match table.

 

Related to my original question, would I be able to parse the HTML if it contains PHP calls? Would the calls be replaced by their return values or would they be passed through as raw PHP? To explain it better, I have function getPurchaseOrder() which returns all the HTML with a few other PHP calls in there like getting the customer's name and phone number. Is the name already obtained when I get the return from getPurchaseOrder() or is it done when rendered by the browser?

Link to comment
Share on other sites

Since I have no idea what your pages / forms look like, nor what your functions do, I'll explain the process I eluded to from the beginning.

 

The salesman has a web FORM with various inputs, each pertaining to the items the customer may purchase.  Since you mentioned lumber, let's say you have three sets of Lumber *size* and a Quantity for such.

 

The salesman selects 2x4x10 - 100 qty, 2x2x10 - 30 qty, and 4x4x10 - 25 qty.  Salesman then finishes the form off with the personal details of the client.

 

Since a client could have multiple purchase orders, you would have two database tables, Customers and Orders.

 

Your Customers table would look similar to:

customer_id | customer_name | customer_phone | customer_address 

 

Depending on how many purchasable items and how you want to recall such information, The (barbaric) Order table would look similar to:

order_id | customer_id | salesman_id | lumber2_4_10 | lumber2_2_10 | lumber4_4_10

 

Where the values for the rows are all integers.  You could go much further in your database design depending on your needs with things like storing the values serialized by type (lumber_sticks, lumber_flat, etc), a table for each sellable item where you could manage their price independently, and so many more variations.  But I digress.

 

So for this hypothetical situne, Let's populate these tables:

customer_id | customer_name | customer_phone | customer_address 
------------------------------------------------------------------
     1      |    John Doe   | (212) 555-1000 | 123 Elm Street

order_id | customer_id | salesman_id | lumber2_4_10 | lumber2_2_10 | lumber4_4_10
--------------------------------------------------------------------------------
   43    |      1      |      84     |     100      |       30     |       25

 

When John Doe (or a salesman) wants to review the order, PHP makes a SQL request to pull the order number and the associated customer.  With your PHP statement loaded with all of that information, you can create your table:

 

order_review.php

<table>
    <thead>
        <tr>
            <th><p>
                <?php echo $row['customer_name'] . '<br />' . $row['customer_address'] . '<br />' . $row['customer_phone'];?>
            </p></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Lumber 2x4x10</td>
            <td><?php echo $row['lumber2_4_10'];?></td>
        </tr>
        ...
    </tbody>
</table>

This view is informational only, and is what I imagine you are using to generate your PDF.

 

You can further add a button or link to edit the information, which opens a new page (order_update.php) that replaces the information with FORM Inputs and loads the stored values. 

 

Once the update is complete, you would reload order_review.php for verification and when satisfied, the client can submit their order which regenerates the PDF (without your form inputs).

Link to comment
Share on other sites

Since a client could have multiple purchase orders, you would have two database tables, Customers and Orders.

 

Your Customers table would look similar to:

customer_id | customer_name | customer_phone | customer_address 

 

Depending on how many purchasable items and how you want to recall such information, The (barbaric) Order table would look similar to:

order_id | customer_id | salesman_id | lumber2_4_10 | lumber2_2_10 | lumber4_4_10

 

Where the values for the rows are all integers.  You could go much further in your database design depending on your needs with things like storing the values serialized by type (lumber_sticks, lumber_flat, etc), a table for each sellable item where you could manage their price independently, and so many more variations.  But I digress.

 

So for this hypothetical situne, Let's populate these tables:

customer_id | customer_name | customer_phone | customer_address 
------------------------------------------------------------------
     1      |    John Doe   | (212) 555-1000 | 123 Elm Street

order_id | customer_id | salesman_id | lumber2_4_10 | lumber2_2_10 | lumber4_4_10
--------------------------------------------------------------------------------
   43    |      1      |      84     |     100      |       30     |       25

 

I have this. I have a customer table which stores all the customer information when the quote is done. There's also a building_products table which stores every product used and all associated attributes/prices for each one. Then there's a match_building_product table which matches each quote with all the products/prices/sizes used for that quote. It's this match_building_product table which information is pulled from in order to create each purchase order. So thank you, it's good to know I did it correctly.

 

 

You can further add a button or link to edit the information, which opens a new page (order_update.php) that replaces the information with FORM Inputs and loads the stored values. 

 

Once the update is complete, you would reload order_review.php for verification and when satisfied, the client can submit their order which regenerates the PDF (without your form inputs).

 

This is what I've been trying to explain since the beginning that I'm trying to avoid. Right now I have one single function (or it could be a page) which has the layout for the purchase order and generates it as needed. If I have one page to display it and another to edit it, any changes to the layout of the purchase order would need to be done in both places. I have a single function to avoid this, I want to use just the one function for both so any edits only need to be done in the one place.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.