Receiving a POST data

Thread Solved

Join Date: Apr 2008
Posts: 491
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

Receiving a POST data

 
0
  #1
Oct 12th, 2009
Hi,

We can code this way to print something if Exit button is clicked.
  1. <form action="process.php" method="POST">
  2. <input type="hidden" name="hiddenName" value="Jolly" />
  3. <input type="submit" name="submit" value="Exit" />
  4. </form>
  5.  
  6. if($_POST["submit"] == "Exit") {
  7. echo $_POST["hiddenName"];
  8. }

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

  1. <form name="formExit" action="process.php" method="POST">
  2. <input type="hidden" name="hiddenName" value="Jolly" />
  3. <a href="#" onclick="document.formExit.submit()" title="Exit">EXIT</a>
  4. </form>
  5.  
  6. if( ???????????? == "Exit") {
  7. echo $_POST["hiddenName"];
  8. }

Thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey
 
0
  #2
Oct 12th, 2009
Originally Posted by veledrom View Post
Hi,

We can code this way to print something if Exit button is clicked.
  1. <form action="process.php" method="POST">
  2. <input type="hidden" name="hiddenName" value="Jolly" />
  3. <input type="submit" name="submit" value="Exit" />
  4. </form>
  5.  
  6. if($_POST["submit"] == "Exit") {
  7. echo $_POST["hiddenName"];
  8. }

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

  1. <form name="formExit" action="process.php" method="POST">
  2. <input type="hidden" name="hiddenName" value="Jolly" />
  3. <a href="#" onclick="document.formExit.submit()" title="Exit">EXIT</a>
  4. </form>
  5.  
  6. if( ???????????? == "Exit") {
  7. echo $_POST["hiddenName"];
  8. }

Thanks in advance
  1. <script type="text/javascript">
  2. function submitForm(val)
  3. {
  4. document.getElementById('submitted').value = val;
  5. document.getElementById('submitted').form.submit();
  6. }
  7. </script>
  8. <form action="process.php" method="post">
  9. <input type="hidden" name="submitted" id="submitted" value="" />
  10. <a href="#" onclick="submitForm('EXIT');">EXIT</a>
  11. </form>
Last edited by ShawnCplus; Oct 12th, 2009 at 1:34 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 4
Reputation: jpdbaugh is an unknown quantity at this point 
Solved Threads: 1
jpdbaugh jpdbaugh is offline Offline
Newbie Poster
 
-1
  #3
Oct 13th, 2009
  1.  
  2. <form name="formExit" action="process.php" method="POST">
  3. <input type="hidden" name="hiddenName" value="Jolly" />
  4. <a href="#" onclick="document.formExit.submit()" title="Exit">EXIT</a>
  5. </form>
  6.  
  7. if( ???????????? == "Exit") {
  8. echo $_POST["hiddenName"];
  9. }
  1. foreach $_POST as $key -> $value {
  2. if ($value == 'Exit')
  3. $echo $_POST['hiddename'];
  4. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey
 
0
  #4
Oct 13th, 2009
Originally Posted by jpdbaugh View Post
  1. foreach $_POST as $key -> $value {
  2. if ($value == 'Exit')
  3. $echo $_POST['hiddename'];
  4. }
Holy crap no. Just no. A thousand times no.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 4
Reputation: jpdbaugh is an unknown quantity at this point 
Solved Threads: 1
jpdbaugh jpdbaugh is offline Offline
Newbie Poster
 
0
  #5
Oct 14th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 521
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 61
network18 network18 is offline Offline
Posting Pro
 
0
  #6
Oct 14th, 2009
  1. if(isset($_POST["submit"] ) && $_POST["submit"] == "Exit")
  2. {
  3. //your code here
  4. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 491
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training
 
0
  #7
Oct 14th, 2009
Thanks to ShawnCplus. Solved.

  1. <script type="text/javascript">
  2. function submitForm(val) {
  3. document.getElementById('submittedName').form.submit();
  4. }
  5. </script>
  6.  
  7. <form action="process.php" method="post">
  8. <input type="hidden" name="hiddenName" id="submittedName" value="Jolly" />
  9. <a href="#" onclick="submitForm('this.hiddenName');">SUBMIT</a>
  10. </form>

  1. <?php
  2. echo $_POST["hiddenName"];
  3. ?>
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey
 
0
  #8
Oct 14th, 2009
Originally Posted by veledrom View Post
Thanks to ShawnCplus. Solved.

  1. <script type="text/javascript">
  2. function submitForm(val) {
  3. document.getElementById('submittedName').form.submit();
  4. }
  5. </script>
  6.  
  7. <form action="process.php" method="post">
  8. <input type="hidden" name="hiddenName" id="submittedName" value="Jolly" />
  9. <a href="#" onclick="submitForm('this.hiddenName');">SUBMIT</a>
  10. </form>

  1. <?php
  2. echo $_POST["hiddenName"];
  3. ?>
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()
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC