Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Navigation from a PHP form

Navigation from a PHP form

Scheduled Pinned Locked Moved JavaScript
javascriptphpalgorithmshelpquestion
7 Posts 2 Posters 15 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MacRaider4
    wrote on last edited by
    #1

    I hope this is the right place for this. I've been looking for quite a while for something remotely similar to what I would like to do and no such luck (probably looking for the wrong thing). I'm just learning PHP and haven't done anything in Javascript in about 10 years so I'm beyond rusty :confused: I'm building a calendar and what I want to do is get the navigation to work to move forward and backwards through the month. I kinda have it working in PHP but it's getting convoluted, and with the searching I've been doing a lot of people are saying to use Javascript. Only problem is I can't seem to find anything as far as examples go. I basically need to send a few variables to the next page based on which of the two buttons I select. Anyone know where I can find a good article? I either need to send the motifiers for the month and year or the new month and year. Thanks in advance!!

    C 1 Reply Last reply
    0
    • M MacRaider4

      I hope this is the right place for this. I've been looking for quite a while for something remotely similar to what I would like to do and no such luck (probably looking for the wrong thing). I'm just learning PHP and haven't done anything in Javascript in about 10 years so I'm beyond rusty :confused: I'm building a calendar and what I want to do is get the navigation to work to move forward and backwards through the month. I kinda have it working in PHP but it's getting convoluted, and with the searching I've been doing a lot of people are saying to use Javascript. Only problem is I can't seem to find anything as far as examples go. I basically need to send a few variables to the next page based on which of the two buttons I select. Anyone know where I can find a good article? I either need to send the motifiers for the month and year or the new month and year. Thanks in advance!!

      C Offline
      C Offline
      cjoki
      wrote on last edited by
      #2

      You can send values from one page to another by either a get or a post. A get is just added to the link and a post can be down by making it use hidden inputs and javascript to fill in the selected values and form submition. Hope that helps.

      Chris J www.redash.org

      M 1 Reply Last reply
      0
      • C cjoki

        You can send values from one page to another by either a get or a post. A get is just added to the link and a post can be down by making it use hidden inputs and javascript to fill in the selected values and form submition. Hope that helps.

        Chris J www.redash.org

        M Offline
        M Offline
        MacRaider4
        wrote on last edited by
        #3

        Good points but I haven't done lore than about 50 hours of web programming since 2001 so lets see if I got this right. Are you saying to use the javascript on (lets say) the new form vs the original? The way I have it now is "calendar" is based off the current Date to populate the calendar grid. If you choose Next Month it goes to calendar3 which processes the to procedure to add one month. If you choose the previous button it goes to calendar2 which processes the procedure to subtract one month. This is resulting in a lot of duplicate code. However if I can do the work within in javascript I can keep all the code centralized and just pass over the "new date". Maybe I can do that now but I'm not sure (new guy problem), but I'd still have 3 pages vs maybe 1 or 2. I'm thinking it would be more like "if buttonNext is clicked do this, else do this" (this is how I did it in ASP, but my boss refuses to run IIS so I had to scrap that project and go to PHP and apparently Javascript). I'm not seeing a way of doing that in PHP thus the reason I'm looking to javascript. Does that help describe my problem better?

        C 1 Reply Last reply
        0
        • M MacRaider4

          Good points but I haven't done lore than about 50 hours of web programming since 2001 so lets see if I got this right. Are you saying to use the javascript on (lets say) the new form vs the original? The way I have it now is "calendar" is based off the current Date to populate the calendar grid. If you choose Next Month it goes to calendar3 which processes the to procedure to add one month. If you choose the previous button it goes to calendar2 which processes the procedure to subtract one month. This is resulting in a lot of duplicate code. However if I can do the work within in javascript I can keep all the code centralized and just pass over the "new date". Maybe I can do that now but I'm not sure (new guy problem), but I'd still have 3 pages vs maybe 1 or 2. I'm thinking it would be more like "if buttonNext is clicked do this, else do this" (this is how I did it in ASP, but my boss refuses to run IIS so I had to scrap that project and go to PHP and apparently Javascript). I'm not seeing a way of doing that in PHP thus the reason I'm looking to javascript. Does that help describe my problem better?

          C Offline
          C Offline
          cjoki
          wrote on last edited by
          #4

          It can be done in php. Try making a test project in php that has the basic function of what you are trying to do. For example have a counter with a plus and minus button, and a input field to hold a value. I will give you a sample form to play with.

          <?php
          if(isset($_POST))
          {
          if($_POST['action']=='+')
          {
          $counter++;
          }
          else if($_POST['action']=='-')
          {
          $counter--;
          }
          else
          {
          // ...
          }
          }
          else
          {
          $counter = 0;
          }

          echo "<form action='' method='post'>";
          echo "<input type='submit' name='action' value='+'>";
          echo "<input type='text' value='".$counter."' name='counter'>";
          echo "<input type='submit' name='action' value='-'>";
          echo "</form>"

          ?>

          This should increase or decrease the counter with each click of the buttons + or -. This behaviour is like the next or prior month buttons your wrote about. You will of course need to add bound checking for the months. If you get this going you should be able to expand on it to handle the calander.

          Chris J www.redash.org

          M 2 Replies Last reply
          0
          • C cjoki

            It can be done in php. Try making a test project in php that has the basic function of what you are trying to do. For example have a counter with a plus and minus button, and a input field to hold a value. I will give you a sample form to play with.

            <?php
            if(isset($_POST))
            {
            if($_POST['action']=='+')
            {
            $counter++;
            }
            else if($_POST['action']=='-')
            {
            $counter--;
            }
            else
            {
            // ...
            }
            }
            else
            {
            $counter = 0;
            }

            echo "<form action='' method='post'>";
            echo "<input type='submit' name='action' value='+'>";
            echo "<input type='text' value='".$counter."' name='counter'>";
            echo "<input type='submit' name='action' value='-'>";
            echo "</form>"

            ?>

            This should increase or decrease the counter with each click of the buttons + or -. This behaviour is like the next or prior month buttons your wrote about. You will of course need to add bound checking for the months. If you get this going you should be able to expand on it to handle the calander.

            Chris J www.redash.org

            M Offline
            M Offline
            MacRaider4
            wrote on last edited by
            #5

            Sorry for the delay, we've been having some bad network issues (bad router). I finally have some time to look at this. Looks pretty straight forward, but I'll let you know if I have any more questions.

            1 Reply Last reply
            0
            • C cjoki

              It can be done in php. Try making a test project in php that has the basic function of what you are trying to do. For example have a counter with a plus and minus button, and a input field to hold a value. I will give you a sample form to play with.

              <?php
              if(isset($_POST))
              {
              if($_POST['action']=='+')
              {
              $counter++;
              }
              else if($_POST['action']=='-')
              {
              $counter--;
              }
              else
              {
              // ...
              }
              }
              else
              {
              $counter = 0;
              }

              echo "<form action='' method='post'>";
              echo "<input type='submit' name='action' value='+'>";
              echo "<input type='text' value='".$counter."' name='counter'>";
              echo "<input type='submit' name='action' value='-'>";
              echo "</form>"

              ?>

              This should increase or decrease the counter with each click of the buttons + or -. This behaviour is like the next or prior month buttons your wrote about. You will of course need to add bound checking for the months. If you get this going you should be able to expand on it to handle the calander.

              Chris J www.redash.org

              M Offline
              M Offline
              MacRaider4
              wrote on last edited by
              #6

              This seems to work good for this example, I did however make the following changes for this page:

              echo 'counter = ' .$counter = $_POST['counter'];

              if(isset($_POST))
              {
              if($_POST['action']=='+')
              {
              //echo "If";
              $counter++;
              echo $counter;
              }
              else if($_POST['action']=='-')
              {
              etc.......

              after a few tries I realized it wasn't receiving $counter so I added the $counter = $_POST part and that seems to have fixed it, so maybe I can get away with just one page afterall which would be super.

              C 1 Reply Last reply
              0
              • M MacRaider4

                This seems to work good for this example, I did however make the following changes for this page:

                echo 'counter = ' .$counter = $_POST['counter'];

                if(isset($_POST))
                {
                if($_POST['action']=='+')
                {
                //echo "If";
                $counter++;
                echo $counter;
                }
                else if($_POST['action']=='-')
                {
                etc.......

                after a few tries I realized it wasn't receiving $counter so I added the $counter = $_POST part and that seems to have fixed it, so maybe I can get away with just one page afterall which would be super.

                C Offline
                C Offline
                cjoki
                wrote on last edited by
                #7

                Yeah, sorry I forgot to add the $_POST value for the counter, my bad. Anyways, on a side note you will want to validate the info being used by your post before you use it or you open yourself to sql injection attacks. You can use a number of ways to scrub input sent to php and you can google the issue to find all manor of sound advice on the net and the php forum here :)

                Chris J www.redash.org

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups