submit and isset

Thread Solved

Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

submit and isset

 
0
  #1
Sep 29th, 2008
I have this chronic problem with my php file, though I have made a lot research about the submit buttons and isset and $_POST part of the problem still persist. For you to understand and probably point out my mistakes, i have enclosed the script below:

  1. <?php
  2. $m = (!$m) ? date("m",mktime()) : "$m";
  3. $y = (!$y) ? date("Y",mktime()) : "$y";
  4.  
  5. if (($_SERVER['REQUEST_METHOD'] == "POST") || ($_SERVER['Submit7'] == "Next"))
  6. {
  7. $eventdate = $_POST['eventdate'];
  8. $stime = $_POST['stime'];
  9. $location = $_POST['locate'];
  10. $mdescription = $_POST['description'];
  11.  
  12. header('location:next.php');
  13. exit();
  14. }else if (($_SERVER['REQUEST_METHOD'] == "POST") || ($_SERVER['Submit6'] == "Reset"))
  15. {
  16. header('location: myfile.php');
  17. exit();
  18. }
  19.  
  20. ?>
  21. <html>
  22. <table>
  23. <tr>
  24. <!-- calling the function to draw the calendar -->
  25. <td valign="top"><?php cal($_GET['m'],$_GET['y']); ?></td>
  26. <td width="25" nowrap><br /></td>
  27. <td> </td>
  28. <td>
  29. <!-- the second column of the table starts here -->
  30. <!-- -->
  31. <form name="me" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  32. <table cellpadding="0" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
  33. <table cellpadding="4" cellspacing="1" border="0 "bgcolor="#FFFFFF">
  34. <tr><td colspan="2" bgcolor="#3399FF"><font size="+1" color="#FFFFFF"><b>Request Form</b></font></td></tr>
  35. <tr><td><b>Date for Event: </b></td><td><input type="text" name="eventdate" value="" size="12"> <font size="2">dd/mm/yyyy</font></td></tr>
  36. <tr>
  37. <td><b>Start Time:</b></td>
  38. <td><input type="text" name="stime"> 24 Hour Format ie.1125 </td>
  39. </tr>
  40. <tr>
  41. <td><b>Location:</b></td>
  42. <td><input type="text" name="locate">20 Characters</td>
  43. </tr>
  44. <tr>
  45. <td><b> Description:</b></td>
  46. <td><textarea name="descrption"></textarea></td>
  47. </tr>
  48. <tr>
  49. <td colspan="2" bgcolor="#3399FF"><div align="center">
  50. <input type="submit" name="Submit6" method="POST" value="Reset"> &nbsp; &nbsp; &nbsp; &nbsp;
  51. <input type="submit" method="post" name="Submit7" value="Next">
  52. </td>
  53. </tr>
  54. </table></form>
  55. </table>
  56. </blockquote>
  57. </body>
  58. </html>
  59. <?php>

the problem is with processing the reset and next buttons - I have tried several options and neither solves the problem.
Last edited by peter_budo; Sep 30th, 2008 at 5:40 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: submit and isset

 
0
  #2
Sep 29th, 2008
Make sure you put your code in code tags.

  1. if (($_SERVER['REQUEST_METHOD'] == "POST") || ($_SERVER['Submit7'] == "Next"))
  2. {
  3. $eventdate = $_POST['eventdate'];
  4. $stime = $_POST['stime'];
  5. $location = $_POST['locate'];
  6. $mdescription = $_POST['description'];
  7.  
  8. header('location:next.php');
  9. exit();
  10. }
Would it not be better to replace the IF statement with
  1. if (isset($_POST['Submit7'])) {
This will check whether the submit button has been clicked, also I don't believe $_SERVER can be used to check form fields, check http://uk3.php.net/manual/en/reserve...les.server.php.

Also, can I ask why you aren't using the reset button in HMTL? <input type="reset"> as this will clear all fields in the form.
Last edited by Will Gresham; Sep 29th, 2008 at 7:16 pm.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

Re: submit and isset

 
0
  #3
Sep 29th, 2008
Originally Posted by xan View Post
Make sure you put your code in code tags.

  1. if (($_SERVER['REQUEST_METHOD'] == "POST") || ($_SERVER['Submit7'] == "Next"))
  2. {
  3. $eventdate = $_POST['eventdate'];
  4. $stime = $_POST['stime'];
  5. $location = $_POST['locate'];
  6. $mdescription = $_POST['description'];
  7.  
  8. header('location:next.php');
  9. exit();
  10. }
Would it not be better to replace the IF statement with
  1. if (isset($_POST['Submit7'])) {
This will check whether the submit button has been clicked, also I don't believe $_SERVER can be used to check form fields, check http://uk3.php.net/manual/en/reserve...les.server.php.

Also, can I ask why you aren't using the reset button in HMTL? <input type="reset"> as this will clear all fields in the form.
Thanks for the reply, I must admit i am a beginner and having tried so many options had gotten me eventually confused.

will try your options and get back ASAP
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

Re: submit and isset

 
0
  #4
Sep 29th, 2008
Hi Xan,

I have worked on the script after your last input and have changed the $_SERVER to:

  1. if(isset($submit)== 'Next')
  2. {
  3. $eventdate = $_POST['eventdate'];
  4. $stime = $_POST['stime'];
  5. $location = $_POST['locate'];
  6. $mdescription = $_POST['description'];
  7. }

The reset works, but when I click on the next button, it seems to function just like the reset.
Last edited by peter_budo; Sep 30th, 2008 at 5:40 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: submit and isset

 
0
  #5
Sep 29th, 2008
Not quite

$_POST['xx'] is the item to use for the if statement.

What this does is gets the value for the field in the form which is named in quotes.

You don't need anything but <input type="submit" name="Submit7" value="Next" /> for the submit button, the method=post is defined by the <form> tag.

All you need for the if statement is the code I posted earlier, if (isset($_POST['Submit7'])) { this says 'If Submit7 has been pressed, run the following code'.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

Re: submit and isset

 
0
  #6
Sep 29th, 2008
Thanks Xan, I now have an understanding of how the implementation should be, however, after several trials the next button seem only reset the page. could it be a prblem with the form tag?
1. <form name="me" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

I changed it to
2. <form name="me" method="POST" action="<? echo $PHP_SELF; ?> > and the error after submitting the next button is
Forbidden
You don't have permission to access /myclass/< on this server.

Dont you think am not doing something right?

sorry for being a pain.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: submit and isset

 
0
  #7
Sep 29th, 2008
I have broken up the code with the required changes as below:
  1. <?php
  2. $m = (!$m) ? date("m",mktime()) : "$m";
  3. $y = (!$y) ? date("Y",mktime()) : "$y";
Changes Here
  1. if (isset($_POST['Submit7']))
  1. {
  2. $eventdate = $_POST['eventdate'];
  3. $stime = $_POST['stime'];
  4. $location = $_POST['locate'];
  5. $mdescription = $_POST['description'];
  6.  
  7. header('location:next.php');
  8. exit();
  9. }
Remove reset code
  1.  
  2. ?>
  3. <html>
  4. <table>
  5. <tr>
  6. <!-- calling the function to draw the calendar -->
  7. <td valign="top"><?php cal($_GET['m'],$_GET['y']); ?></td>
  8. <td width="25" nowrap><br /></td>
  9. <td> </td>
  10. <td>
  11. <!-- the second column of the table starts here -->
  12. <!-- -->
  13. <form name="me" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  14. <table cellpadding="0" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
  15. <table cellpadding="4" cellspacing="1" border="0 "bgcolor="#FFFFFF">
  16. <tr><td colspan="2" bgcolor="#3399FF"><font size="+1" color="#FFFFFF"><b>Request Form</b></font></td></tr>
  17. <tr><td><b>Date for Event: </b></td><td><input type="text" name="eventdate" value="" size="12"> <font size="2">dd/mm/yyyy</font></td></tr>
  18. <tr>
  19. <td><b>Start Time:</b></td>
  20. <td><input type="text" name="stime"> 24 Hour Format ie.1125 </td>
  21. </tr>
  22. <tr>
  23. <td><b>Location:</b></td>
  24. <td><input type="text" name="locate">20 Characters</td>
  25. </tr>
  26. <tr>
  27. <td><b> Description:</b></td>
  28. <td><textarea name="descrption"></textarea></td>
  29. </tr>
  30. <tr>
  31. <td colspan="2" bgcolor="#3399FF"><div align="center">
Changes Here
  1. <input type="reset" name="Submit6" value="Reset"> &nbsp; &nbsp; &nbsp; &nbsp;
  2. <input type="submit" name="Submit7" value="Next">
  1. </td>
  2. </tr>
  3. </table></form>
  4. </table>
  5. </blockquote>
  6. </body>
  7. </html>

This should do what you want.
Last edited by Will Gresham; Sep 29th, 2008 at 9:31 pm.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

Re: submit and isset

 
0
  #8
Sep 29th, 2008
Xan,

Many regards, its working perfectly - each of the buttons are doing what they are meant to.

going to beef it up with the needed items.

Thanks
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: submit and isset

 
0
  #9
Sep 29th, 2008
No problem, make sure you mark finished topics as solved
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
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