Newbie trying to figure out how to use a form correctly

Newbie trying to figure out how to use a form correctly

am 11.11.2007 22:56:30 von pnberry

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:

session_start();

include ("../settings.php");
$db = mysql_connect("$server", "$username", "$password");
mysql_select_db("$database",$db);

print '';
print '';

#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 "

\"transaction_form\">";
print '';
print '';
print '';
print '';
print '';
print '';
print '';
print '';
print '';
print "";
print '';
#Headers for next row
print '';
print '';
print '';
print '';
print '';
print '';
print '';

#recyclables row
print ''; #WHAT, the item
name
print ''; #Quantity field
print '';
#Scale Button TODO
print ''; #Tare weight field
print ''; #Price per pound
print ""; #Amount due field
print '';
#Update button
print '';

#trash row
print ''; #WHAT, the item name
print ''; #Quantity field
print '';
#Scale Button TODO
print ''; #Tare weight field
print ''; #Price per pound
print ""; #Amount due field
print '';
#Update button
print '';
print '

Transaction Form

caption>';

#Date information
print '
Date   value="now" align=left> NowYYYY-MM-DD
Custom \"$_SESSION[custom_date]\">

Item NameQuantity th>';
print '
Tare Wt$ Per UnitAmount Due th>';
print '
Recyclables - simple rate  value="' . $_SESSION['recy_tare'].'">$
\$$_SESSION[recy_amount_due]
Trash  value="' . $_SESSION['trsh_tare'].'">$
\$$_SESSION[trsh_amount_due]
';
print '
';

print '';
print '';

#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']);
}
?>

Re: Newbie trying to figure out how to use a form correctly

am 11.11.2007 23:45:58 von zeldorblat

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:
>
> > session_start();
>
> include ("../settings.php");
> $db = mysql_connect("$server", "$username", "$password");
> mysql_select_db("$database",$db);
>
> print '';
> print '';
>
> #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 "

> \"transaction_form\">";
> print '';
> print '';
> print '';
> print '';
> print '';
> print '';
> print '';
> print '';
> print '';
> print "";
> print '';
> #Headers for next row
> print '';
> print '';
> print '';
> print '';
> print '';
> print '';
> print '';
>
> #recyclables row
> print ''; #WHAT, the item
> name
> print ''; #Quantity field
> print '';
> #Scale Button TODO
> print ''; #Tare weight field
> print ''; #Price per pound
> print ""; #Amount due field
> print '';
> #Update button
> print '';
>
> #trash row
> print ''; #WHAT, the item name
> print ''; #Quantity field
> print '';
> #Scale Button TODO
> print ''; #Tare weight field
> print ''; #Price per pound
> print ""; #Amount due field
> print '';
> #Update button
> print '';
> print '

Transaction Form

> caption>';
>
> #Date information
> print '
Date   > value="now" align=left> NowYYYY-MM-DD
Custom > \"$_SESSION[custom_date]\">

Item NameQuantity > th>';
> print '
Tare Wt$ Per UnitAmount Due > th>';
> print '
Recyclables - simple rate  > value="' . $_SESSION['recy_tare'].'">$
>
\$$_SESSION[recy_amount_due]
Trash  > value="' . $_SESSION['trsh_tare'].'">$
>
\$$_SESSION[trsh_amount_due]
';
> print '
';
>
> print '';
> print '';
>
> #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.