|
Posted by ZeldorBlat on 11/11/07 22:45
On Nov 11, 4:56 pm, pnbe...@gmail.com wrote:
> Hello,
>
> I'm creating a form for data entry. Specifically, data entry via a
> digital scale for a POS like system (using a serial interface or using
> manual entry via a keyboard which is all I am doing now - I'll worry
> about the scale once I get this problem sorted out...).
> Anyway there is a quantity (weight in pounds) field, a tare weight
> field, a price per pound field and a total charges field. I type in
> values to the quantity and tare weight fields and there is a default
> price per pound rate. When I press the submit ("Update") button the
> total charges field displays the price per pound *(quantity - tare
> weight) . All this is simple enough and it works BUT it takes TWO
> clicks of the submit button to display any changes in the total
> charges field when I change either the quantity or tare weights. What
> am I missing or mis-understanding here? How would I make it so all it
> takes is one click of the submit ("Update") button to display the
> correct amount in the amount_due field?
>
> Hope this makes sense. Thanks for any help or input, I really
> appreciate it.
>
> Paul
>
> Here's my form code:
>
> <?php
> session_start();
>
> include ("../settings.php");
> $db = mysql_connect("$server", "$username", "$password");
> mysql_select_db("$database",$db);
>
> print '<html>';
> print '<body>';
>
> #Sticky data
> #Custom Date
> if (!isset($_SESSION['custom_date'])) {
> $_SESSION['custom_date'] = date('Y-m-d');
> }
> #Recycle values
> if (!isset($_SESSION['recy_quantity'])) {
> $_SESSION['recy_quantity'] = 0;
> }
> $_SESSION['recy_quantity'] = $_GET['recy_quantity'];
>
> if (!isset($_SESSION['recy_tare'])) {
> $_SESSION['recy_tare'] = 0;
> }
> $_SESSION['recy_tare'] = $_GET['recy_tare'];
> #Trash values
> if (!isset($_SESSION['trsh_quantity'])) {
> $_SESSION['trsh_quantity'] = 0;
> }
> $_SESSION['trsh_quantity'] = $_GET['trsh_quantity'];
>
> if (!isset($_SESSION['trsh_tare'])) {
> $_SESSION['trsh_tare'] = 0;
> }
> $_SESSION['trsh_tare'] = $_GET['trsh_tare'];
>
> #Main entry form body
> print "<form action=\"$_SERVER[PHP_SELF]\" method=\"GET\" name=
> \"transaction_form\">";
> print '<table align=center bgcolor="#CDCDCDCD">';
> print '<caption valign=top align=center><h3>Transaction Form</h3></
> caption>';
>
> #Date information
> print '<tr>';
> print '<td></td>';
> print '<th rowspan=2>Date  </th>';
> print '<td align=left><input type=radio name=date checked="checked"
> value="now" align=left> Now</td><th>YYYY-MM-DD</th>';
> print '</tr>';
> print '<tr>';
> print '<td></td>';
> print '<td><input type=radio name=date value="custom"> Custom</td>';
> print "<td><input type=text name=\"custom_date\" size=10 value=
> \"$_SESSION[custom_date]\"></td>";
> print '</tr>';
> #Headers for next row
> print '<tr><th colspan=7><hr></th></tr>';
> print '<tr><th align=center>Item Name</th>';
> print '<th align=center>Quantity</th>';
> print '<th align=left><img src=../images/spacer.gif width=0 height=0></
> th>';
> print '<th align=center>Tare Wt</th>';
> print '<th align>$ Per Unit</th>';
> print '<th align=center>Amount Due</th>';
> print '<th align=left><img src=../images/spacer.gif width=0 height=0></
> th>';
> print '</tr>';
>
> #recyclables row
> print '<tr><td>Recyclables - simple rate </td>'; #WHAT, the item
> name
> print '<td><input type=text name="recy_quantity" size="9" value="' .
> $_SESSION['recy_quantity'].'"></td>'; #Quantity field
> print '<td><button type=button name=scale>Use Scale</button></td>';
> #Scale Button TODO
> print '<td align="center"><input type=text name="recy_tare" size="4"
> value="' . $_SESSION['recy_tare'].'"></td>'; #Tare weight field
> print '<td>$<input type=text size="8" value="0.20" name="recy_price">
> </td>'; #Price per pound
> print "<td>\$$_SESSION[recy_amount_due]</td>"; #Amount due field
> print '<td><button type=submit name=update value=update>Update</td>';
> #Update button
> print '</tr>';
>
> #trash row
> print '<tr><td>Trash </td>'; #WHAT, the item name
> print '<td><input type=text name="trsh_quantity" size="9" value="' .
> $_SESSION['trsh_quantity'].'"></td>'; #Quantity field
> print '<td><button type=button name=scale>Use Scale</button></td>';
> #Scale Button TODO
> print '<td align="center"><input type=text name="trsh_tare" size="4"
> value="' . $_SESSION['trsh_tare'].'"></td>'; #Tare weight field
> print '<td>$<input type=text size="8" value="0.15" name="trsh_price">
> </td>'; #Price per pound
> print "<td>\$$_SESSION[trsh_amount_due]</td>"; #Amount due field
> print '<td><button type=submit name=update value=update>Update</td>';
> #Update button
> print '</tr>';
> print '</table>';
> print '</form>';
>
> print '</body>';
> print '</html>';
>
> #Form processing
> if (isset($_GET['recy_quantity'])) {
> $_SESSION['recy_amount_due'] =
> $_GET['recy_price']*($_GET['recy_quantity'] - $_GET['recy_tare']);
> }
> if (isset($_GET['trsh_quantity'])) {
> $_SESSION['trsh_amount_due'] =
> $_GET['trsh_price']*($_GET['trsh_quantity'] - $_GET['trsh_tare']);
> }
> ?>
Think about what's happening here:
1) Retrieve previously stored values from $_SESSION
2) Draw the form using those values
3) Update $_SESSION with values from $_GET
If you want to see your changes after pressing the submit button the
first time, you probably want to do 3, then 1, then 2.
Navigation:
[Reply to this message]
|