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

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>
<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'];
}
foreach $_POST as $key -> $value {
if ($value == 'Exit')
$echo $_POST['hiddename'];
}

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

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.

if(isset($_POST["submit"] ) && $_POST["submit"] == "Exit")
{
//your code here
}

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"];
?>

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()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.