0

This is the project I need to finish. I am fairly new to php and this project has got me confused. Any help would be greatly appreciated

I am trying to do a Web form that is taking an online order form!

This is What I have so far:

This is the input page or html page:

<form method="POST" action="OnlineOrders.php">

<table border=0>
<tr>
<td width=260>NameE<br /></td>
<td width=295>Descripation<br /></td>
<td width=45>Price<br /></td>
<td width=35>Quanity<br /></td>
</tr>
<tr>

<td>Shirts</td>
<td>Red</td>
<td align="right">$11.50</td>
<td align="center"><input type="text" name="shirt" size="3" maxlength="3" /></td>
</tr>

<tr>
<td>Pants</td>
<td>blue</td>
<td align="right">$23.99</td>
<td align="center"><input type="text" name="pants" size="3" maxlength="3" /></td>
</tr>

<tr>
<td>Shoes</td>
<td>Tennis Show</td>
<td align="right">$35.25</td>
<td align="center"><input type="text" name="shoes" size="3" maxlength="3" /></td>
</tr>

<tr>
<tr>
<td>Coat</td>
<td>Winter coat</td>
<td align="right">$47.50</td>
<td align="center"><input type="text" name="coat" size="3" maxlength="3" /></td>
</tr>

<tr>
<td>Socks</td>
<td>Yellow</td>
<td align="right">$4.99</td>
<td align="center"><input type="text" name="socks" size="3" maxlength="3" /></td>
</tr>

<tr>
<td>Hats</td>
<td>Baseball Cap</td>
<td align="right">$8.99</td>
<td align="center"><input type="text" name="hats" size="3" maxlength="3" /></td>
</tr>

</tr>
</table>
</form>

<br />
<input name="submit" type="submit" value="Submit Order" />
<input type="reset" name="reset" value="Recalculate Order" />
<hr />
<p>
<a href="OrderBoard.php">View Order</a>
</p>



</body>

</html>

********************
The problem is I don't know what to do with the processing page for me to do the rest:
I am taking about OnlineOrders.php

How do i start the Processing page of the program!

4
Contributors
3
Replies
30
Views
3 Years
Discussion Span
Last Post by veedeoo
0

First of all, you need to keep in mind that HTML form data is structured in name/value pairs taken from the form's <input> elements based on the contents of their 'name' and 'value' attributes. When the form is "submitted", that data is sent to the target of the <form> tag's 'action' attribute. In this case, the target is your PHP script file named "OnlineOrders.php", which will need to determine several things: which items are being ordered, the quantity of each item ordered, any options (like size or color), and the respective prices. So your <form> needs to include all of that information in <input> elements as well as displaying it all to the user in a way that makes it clear what each <input> element requires of him/her.

When an order form consists of a list of items, the process can be a little complicated because each ordered product's information must be sent together. So you need to devise a way to encode the 'name' attributes in a way that the PHP script can decipher and identify the information for each individual product. This is often done by using a value for the 'name' attribute that is a combination of the product identifier and which product attribute is being sent. For example, the <input> for a product's quantity might be given the name "shoe_qty", which a PHP script can easily use the explode() function to split on the "_" character to separate the two. For data that is fixed for each item and which doesn't get entered by the user (like the price!), you just use <input type="hidden"> to pass the information.

Once you have your <form> properly constructed, you'll need to write the PHP script to process the information. For that, you should search on "PHP forms tutorial". Pick one. It won't matter much which you choose because the basics are pretty simple. Once you write a script that properly receives and interprets the form data, you should have no trouble figuring out what to do next. Good luck!

0
<form method="POST" action="OnlineOrders.php">
    <table border=0>
        <tr>
            ...............
        </tr>
    </table>
    <br />
    <input name="submit" type="submit" value="Submit Order" />
    <input type="reset" name="reset" value="Recalculate Order" />
</form>
<hr />

Keep in mind all inputs, even the buttons, have to stay in the form you want to submit.

Your OnlineOrders.php will collect the forms data in the $_POST array. For starters try typing this in that file to see what happens:

echo '<pre>';
print_r($_POST);
echo '</pre>';

Once you see what's going on there and what is going where you'll need to look into the some of the following:
- sanitization
- validation
- sql injection (if you use those values in a database) - prepared statements as an easier solution to that problem

You might also want to consider posting that to the same php file and having different behaviour when some values exist, but that's after you figure out the basics, just remember the option exists^^

0

Dude,

It is my lazy day today.. so, I will be cutting corners here. Instead of writing a 100 lines of codes for your processor, let's do it this way.

Copy codes below onto your OnlineOrders.php

if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit'])){

    echo 'if($_SERVER[\'REQUEST_METHOD\'] == \'POST\' && isset($_POST[\'submit\'])){ <br/>';

        foreach($_POST as $name => $submitted_value){

    echo '$'.$name.' = $_POST[\''.$name.'\']; <br/>';

    }
            echo '}';
        }

Direct your browser to your form page and submit the form. Once the browser is redirected to OnlineOrders.php, you should be looking at PHP codes on the page. Copy those codes and paste it on the OnlineOrders.php and save it as your form processor. You can add a little more codes to save it to your database or anything to serve for your purpose.

I am always amazed what I am capable of whenever I am having a lazy day... :) :)

don't forget to add

<?php

on top of the page... :)

Update:

I just want to add that this part of the codes above

 $submitted_value

That can be referenced later on for validation e.g. integer, empty, null, string, or whatever

Edited by veedeoo: info added.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.