Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. //this is default variable if nothing is submitted with my form
  3. $the_user_garden = "gardens";
  4. ?>
  5.  
  6. <?php
  7. //this is the form that will change the variable
  8. if(isset($_POST['submit']))
  9. {
  10. $the_user_garden = $_POST['sub_garden_1'];
  11. }
  12. ?>
  13. <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
  14. <input type="text" name="sub_garden_1" value="sub_garden_1"><br>
  15. <input type="submit" name="submit" value="Submit Form"><br>
  16. </form>
  17.  
  18. <?php
  19. //this put the new variable value from the form as session variable
  20. $_SESSION['myKey'] = $the_user_garden;
  21. ?>
  22.  
  23. <?php
  24. $author_id = get_current_user_id( );
  25. //this is where I am using the changes variable
  26. if( have_rows($the_user_garden, 'user_'.$author_id) ): ?>
  27.  
  28. <?php
  29. //and here too
  30. while( have_rows($the_user_garden, 'user_'.$author_id) ): the_row(); ?>
  31.  
  32. <?php
  33. add_action('init', 'myStartSession', 1);
  34. add_action('wp_logout', 'myEndSession');
  35. add_action('wp_login', 'myEndSession');
  36.  
  37. function myStartSession() {
  38. if(!session_id()) {
  39. session_start();
  40.  
  41. }
  42. }
  43.  
  44. function myEndSession() {
  45. session_destroy ();
  46. }
  47.  
  48. ?>
  49. <?php
  50. // this is where I need the variable for gravity form(pop up)
  51. if(isset($_SESSION['myKey'])) {
  52. $the_user_garden = $_SESSION['myKey'];
  53. } else {
  54. $the_user_garden = "gardens";
  55.  
  56. }
  57. ?>
  58.  
  59. <?php
  60. //this is where I am using variable
  61. $author_id = get_current_user_id( );
  62. if( have_rows($the_user_garden, 'user_'.$author_id) ): ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement