Navigation from a PHP form
-
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!!
-
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!!
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
-
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
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?
-
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?
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
-
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
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.
-
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
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.
-
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.
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