Forum Moderators: coopster
I have a form for my customers to register for events that my company is sponsoring. Inside the form is a table with various text fields, etc for my customers to fill in.
Some of our events are free, some are not. I built a separate page with the payment fields on it, and had hoped to include it on the registration form when the url passed a parameter of "?charge=yes". I had inserted an if statement in a cell in the table to call the include file.
The if statement works. When my urls is used like above, the include file shows, but it actually shows up on top of my other form, making the page largely unreadable.
Any idea what I'm doing wrong?
Thanks,
Chris
Let's try an example using a simplified index page with a basic table in it.
index.php
<html>
<head><title></title></head>
<body>
<table cellpadding="0" cellspacing="0" border="1">
<tr>
<td>This is</td>
<td>a 2 column table</td>
</tr>
<?php include "extrarows.html";?>
<tr>
<td>This row comes after</td>
<td>our included code</td>
</tr>
</table>
</body>
</html>
Now, the key is when including html code is to remember that the include happens inline. When the page is created it is parsed top to bottom. When the line with the include is hit, apache goes and grabs the code from that file and puts it into the page exactly where the include is placed.
That means that our included file will only have partial html in it. It will not be a full page on its own. Therefore no html, head, title or body tags as they have already occurred before our file was included. We must be careful to ensure that the resulting html that is sent to the browser is complete and properly constructed.
Let's look at what be in our 'extrarows.html' file. Let's say we want to include an extra row of data
extrarows.html
<!-- start included data -->
<tr>
<td>this is our extra</td>
<td>row of data</td>
</tr>
<!-- end included data -->
We have to make sure that we have our row tags (tr) and the proper number of cells (td) or we will break the table.
If we were to look at the source of the index.php page through the browser we would see something like this
<html>
<head><title></title></head>
<body>
<table cellpadding="0" cellspacing="0" border="1">
<tr>
<td>This is</td>
<td>a 2 column table</td>
</tr>
<!-- start included data -->
<tr>
<td>this is our extra</td>
<td>row of data</td>
</tr>
<!-- end included data -->
<tr>
<td>This row comes after</td>
<td>our included code</td>
</tr>
</table>
</body>
</html>
Our inlcuded file has been inserted into the code where the include statement was located. That is why it is so important to make sure the html is correct. If we had more cells in our included row than the others, or if we didn't include the opening and closing tr tags, the resulting table wouldn't be properly constructed and we would blow it up.
does that help a bit?