944,044 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 737
  • PHP RSS
Oct 12th, 2009
0

Receiving a POST data

Expand Post »
Hi,

We can code this way to print something if Exit button is clicked.
PHP Syntax (Toggle Plain Text)
  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?

PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
Oct 12th, 2009
0
Re: Receiving a POST data
Click to Expand / Collapse  Quote originally posted by veledrom ...
Hi,

We can code this way to print something if Exit button is clicked.
PHP Syntax (Toggle Plain Text)
  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?

PHP Syntax (Toggle Plain Text)
  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
html Syntax (Toggle Plain Text)
  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.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Oct 13th, 2009
-1
Re: Receiving a POST data
Quote ...
PHP Syntax (Toggle Plain Text)
  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. }
PHP Syntax (Toggle Plain Text)
  1. foreach $_POST as $key -> $value {
  2. if ($value == 'Exit')
  3. $echo $_POST['hiddename'];
  4. }
Reputation Points: 10
Solved Threads: 1
Newbie Poster
jpdbaugh is offline Offline
4 posts
since Oct 2009
Oct 13th, 2009
0
Re: Receiving a POST data
Click to Expand / Collapse  Quote originally posted by jpdbaugh ...
PHP Syntax (Toggle Plain Text)
  1. foreach $_POST as $key -> $value {
  2. if ($value == 'Exit')
  3. $echo $_POST['hiddename'];
  4. }
Holy crap no. Just no. A thousand times no.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Oct 14th, 2009
0
Re: Receiving a POST data
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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
jpdbaugh is offline Offline
4 posts
since Oct 2009
Oct 14th, 2009
0
Re: Receiving a POST data
PHP Syntax (Toggle Plain Text)
  1. if(isset($_POST["submit"] ) && $_POST["submit"] == "Exit")
  2. {
  3. //your code here
  4. }
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Oct 14th, 2009
0
Re: Receiving a POST data
Thanks to ShawnCplus. Solved.

PHP Syntax (Toggle Plain Text)
  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>

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. echo $_POST["hiddenName"];
  3. ?>
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
Oct 14th, 2009
0
Re: Receiving a POST data
Click to Expand / Collapse  Quote originally posted by veledrom ...
Thanks to ShawnCplus. Solved.

PHP Syntax (Toggle Plain Text)
  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>

PHP Syntax (Toggle Plain Text)
  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()
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Prevent multiple login Help needed
Next Thread in PHP Forum Timeline: Problem with file Upload ...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC