2 Submit buttons

First i’m gonna paste the code then i’ll explain what the problem is :
[php]



<?php
if (isset($_POST[‘Submit1’])) {
$Value1 = “RandomText”;
}
if (isset($_POST[‘Submit2’])) {
echo $Value1;
}
[/php]

I have 2 Submit buttons, what i want to do is program it in a way that when you click on the FIRST SUBMIT BUTTON, it sets the variable ( in this case $Value1 = “RandomText” ) when you click the SECOND SUBMIT BUTTON, it reads the variable
However when i use this code, i click the first button to set the variable no problem, but when i click the second one, it tells me that the variable ‘Value1’ is not defined
the script above is not the original script, it’s just an exemple i created to simplify the problem
thanks in advance :wink:

Hello,

When you click on the submit button you’re sending your post data to the script, when you click on the post button you’re resubmitting the post data so Value1 becomes unset.

With that said what you’ll want to do is create a hidden field on your form and in the value are check to see if $Value1 is set and if it is to echo $Value1 and give it a name (I’ll use val1). Then when you check to see if the second submit button has been pressed you’ll have to set $Value1 = $_POST[‘val1’] and then you can echo that out.

[php]

<?php if (isset($_POST['Submit1'])) { $Value1 = "RandomText"; } if (isset($_POST['Submit2'])) { $Value1 = $_POST['val1']; } ?>
 <FORM NAME ="form1" METHOD ="POST" ACTION = "">
  <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "First Submit Button"></td>
  <INPUT TYPE = "Submit" Name = "Submit2" VALUE = "Second Submit Button"></td>
      <input type="hidden" name="val1" value="<?php if(isset($Value1)){echo $Value1;}?>">

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service