0

Hi,

We can code this way to print something if Exit button is clicked.

<form action="process.php" method="POST">
<input type="hidden" name="hiddenName" value="Jolly" />
<input type="submit" name="submit" value="Exit" />
</form>

if($_POST["submit"] == "Exit") {
   echo $_POST["hiddenName"];
}

What about if we use this way. How do i check if Exit button was clicked or not?

<form name="formExit" action="process.php" method="POST">
<input type="hidden" name="hiddenName" value="Jolly" />
<a href="#" onclick="document.formExit.submit()" title="Exit">EXIT</a>
</form>

if( ???????????? == "Exit") {
   echo $_POST["hiddenName"];
}

Thanks in advance

4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by ShawnCplus
0

Hi,

We can code this way to print something if Exit button is clicked.

<form action="process.php" method="POST">
<input type="hidden" name="hiddenName" value="Jolly" />
<input type="submit" name="submit" value="Exit" />
</form>

if($_POST["submit"] == "Exit") {
   echo $_POST["hiddenName"];
}

What about if we use this way. How do i check if Exit button was clicked or not?

<form name="formExit" action="process.php" method="POST">
<input type="hidden" name="hiddenName" value="Jolly" />
<a href="#" onclick="document.formExit.submit()" title="Exit">EXIT</a>
</form>

if( ???????????? == "Exit") {
   echo $_POST["hiddenName"];
}

Thanks in advance

<script type="text/javascript">
function submitForm(val)
{
  document.getElementById('submitted').value = val;
  document.getElementById('submitted').form.submit();
}
</script>
<form action="process.php" method="post">
  <input type="hidden" name="submitted" id="submitted" value="" />
  <a href="#" onclick="submitForm('EXIT');">EXIT</a>
</form>

Edited by ShawnCplus: n/a

-1
<form name="formExit" action="process.php" method="POST">
      <input type="hidden" name="hiddenName" value="Jolly" />
      <a href="#" onclick="document.formExit.submit()" title="Exit">EXIT</a>
      </form>
  
      if( ???????????? == "Exit") {
      echo $_POST["hiddenName"];
       }
foreach $_POST as $key -> $value {
if ($value == 'Exit')
$echo $_POST['hiddename'];
}
0
foreach $_POST as $key -> $value {
if ($value == 'Exit')
$echo $_POST['hiddename'];
}

Holy crap no. Just no. A thousand times no.

0

I don't have much experience with PHP as I have only done one useful script with it so far for uploading .PDFs as BLOBS, searching them, and downloading them. I am definitley still learning and I was wondering if you could tell me what is wrong with the technuique I used? Is it more efficient to use javascript than looping through the entire $_POST array? Or is it just not good PHP practice? Thanks.

0

Thanks to ShawnCplus. Solved.

<script type="text/javascript">
function submitForm(val) {
document.getElementById('submittedName').form.submit();
}
</script>

<form action="process.php" method="post">
<input type="hidden" name="hiddenName" id="submittedName" value="Jolly" />
<a href="#" onclick="submitForm('this.hiddenName');">SUBMIT</a>
</form>
<?php
echo $_POST["hiddenName"];
?>
0

Thanks to ShawnCplus. Solved.

<script type="text/javascript">
function submitForm(val) {
document.getElementById('submittedName').form.submit();
}
</script>

<form action="process.php" method="post">
<input type="hidden" name="hiddenName" id="submittedName" value="Jolly" />
<a href="#" onclick="submitForm('this.hiddenName');">SUBMIT</a>
</form>
<?php
echo $_POST["hiddenName"];
?>

That won't actually get you the value of the hiddenName element though. You would have to do document.getElementById('submittedName').value . But since you're not really setting the value anyway you can just remove the val argument altogether and remove 'this.hiddenName' from submitForm()

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.