[nycphp-talk] Can this be done with PHP or JavaScript? Is it even possible?
Analysis & Solutions
danielc at analysisandsolutions.com
Sat Jul 20 19:41:34 EDT 2002
Folks:
On Sat, Jul 20, 2002 at 05:21:20PM -0400, Jim Hendricks wrote:
> Where is the problem with passing all the items? If $submit == "submit1"
> then use $item1 and $amount1 if $submit =="submit2" then use $item2 and
> $amount2.
Jim is right on here. I'd even save a step. Make the value of $submit
an integer, then use that integer to create the name of a variable
variable, from which you get the needed data.
Form...
<input type="hidden" name="item2" value="PA03" />
<input type="submit" name="submit" value="2" />
Script...
$itemvar = "item$submit";
echo 'item chosen is: ' . $$itemvar;
This eliminates the need to go through a lot of if or switch statements
and makes it easy to add and remove items because you don't need to
update those if or switch statements.
> Based on your example also, couldn't item & amount be put into a table &
> based on which button the user pushes determines which record to
> look up to
> populate item and amount?
Again, Jim is on target. This is really the way to go for several
reasons. Most importantly, -- yes, I'm bringing this back to the data
vaidation thread :) -- it keeps people from editing the cost before
submitting the form. Also, it obviates the need for any hidden fields
at all by allowing you to just put the product ID value into the submit
buttons, like this:
<input type="submit" name="ProductID" value="PA03" />
If you don't have database access, you can keep the product information
in a text file or an include file.
Enjoy,
--Dan
--
PHP classes that make web design easier
SQL Solution | Layout Solution | Form Solution
sqlsolution.info | layoutsolution.info | formsolution.info
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list