Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with multiple submit buttons.. help me!!!!

Status
Not open for further replies.

mk2lee1

MIS
Jul 8, 2003
51
US
Hi, i have problem with my code.


In my page there are session variable;

session_start();
session_register("WFCounter");
session_register("TCounter");
session_register("EFactor");

Initially they are set to 0

if(!$WFCounter) $WFCounter=0;
if(!$TCounter) $TCounter=0;
if(!$EFactor) $EFactor=0;

Also, there are 3 submit buttons

<input type=&quot;submit&quot; name=&quot;submit1&quot; value=&quot;Update_UCCP&quot;>
<input type=&quot;submit&quot; name=&quot;submit2&quot; value=&quot;Update_Technical_Factor&quot;>
<input type=&quot;submit&quot; name=&quot;submit3&quot; value=&quot;Update_Environment_Factor&quot;>

And there is validation code that check for validity

if ($WFCounter != 0)
{
check validity for Weight Factor
}

if ($TCounter != 0)
{
check validity for Technical Factor
}

if ($EFactor != 0)
{
check validity for Environmental Factor
}

Initially this would not be checked..
However, if I press the button, let say Update_UCCP button, there is a code that check(page is reloaded into itself using $PHP_SELF) if it was checked, and increases the WFCounter

if(isset($HTTP_POST_VARS['$submit1']))

{
$WFCounter++; //increase the WFCounter
echo &quot;hi&quot;;
}

However, this code doesn't seems to work...

is there any problem with this code?

Please help me thankyou.
 
$WFCounter only exists as long as the page is being displayed, if you move page (even just refreshing the current one) then all variables are reset and you ahev a clean slate. I would suggest writing a hidden form element that is then submitted so you can keep track of the previous value.
 
why three buttons? Does not seem logical to me but I may be wrong, I am not sure what you are trying to do other than increment a var by 1. I may be wrong here because I cannot see just what you are trying to achieve but could you not have one button and some option/radio buttons so that the user can only pick one then use a single submit button and simply check which radio/option button was clicked. Also you check to see which button has been pressed, not entirely sure you can do this but I am going to check now. Ok I have found your error try this
Code:
print “the value of the button pressed is $HTTP_POST_VARS[submit1]”;
but i only had one button sorry should have tryed with 2

in the form tag i had
<form method=&quot;POST&quot;>
see how you go on with this.

To err is human, to completely mess up takes a computer. [morning]
 
ok tryied with 2 buttons
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Log In!&quot;> and
<input type=&quot;submit&quot; name=&quot;submit1&quot; value=&quot;Log out!&quot;>
but i could only get a the value of the last button &quot;log out!&quot;
so i think i may have been correct on the buttons.

To err is human, to completely mess up takes a computer. [morning]
 
csniffer:
Using the follwing HTML:

Code:
<html><body><form action=&quot;/test_code/test_two_submits.php&quot; method=&quot;post&quot;>
<input type=text name=&quot;foo&quot;>
<input type=submit name=&quot;bar1&quot; value=&quot;submit1&quot;>
<input type=submit name=&quot;bar2&quot; value=&quot;submit2&quot;>
</form></body></html>

If I enter a value of &quot;a&quot; in the text input and then click on bar1, $_POST contains:

Code:
Array
(
   [foo] => a
   [bar1] => submit1
)

When I click on bar2, $_POST contains:

Code:
Array
(
   [foo] => a
   [bar2] => submit2
)

This works with Opera, IE, Mozilla, and Netscape.

What browswer are you testing with?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Hi sorry it has taken me so long to get back, although tek-tips said that some messages had been posted, I could not view them.

That’s interesting, I am using IE but it may be how I was addressing the problem. I am going to try this again as I didn’t even get the name only the value of the input tag. But I am relatively new to php. To be honest I just printed the value and didn’t realise that I could view both values. I will have to have a play with these global vars. Thx for pointing that out. I carnt see from the code how u picked up the $_POST into an array could you please explain


To err is human, to completely mess up takes a computer. [morning]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top