Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6713 > unrolled thread
| Started by | mwoolley <trogoz2012@gmail.com> |
|---|---|
| First post | 2012-08-03 07:29 -0700 |
| Last post | 2012-08-06 16:59 +0000 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.lang.php
button, parameter and reload - How do I glue it all together? mwoolley <trogoz2012@gmail.com> - 2012-08-03 07:29 -0700
Re: button, parameter and reload - How do I glue it all together? The Natural Philosopher <tnp@invalid.invalid> - 2012-08-03 16:23 +0100
Re: button, parameter and reload - How do I glue it all together? Jerry Stuckle <jstucklex@attglobal.net> - 2012-08-03 11:35 -0400
Re: button, parameter and reload - How do I glue it all together? Jerry Stuckle <jstucklex@attglobal.net> - 2012-08-03 11:50 -0400
Re: button, parameter and reload - How do I glue it all together? Michael Vilain <vilain@NOspamcop.net> - 2012-08-03 23:00 -0700
Re: button, parameter and reload - How do I glue it all together? mwoolley <trogoz2012@gmail.com> - 2012-08-06 05:47 -0700
Re: button, parameter and reload - How do I glue it all together? Denis McMahon <denismfmcmahon@gmail.com> - 2012-08-06 16:59 +0000
| From | mwoolley <trogoz2012@gmail.com> |
|---|---|
| Date | 2012-08-03 07:29 -0700 |
| Subject | button, parameter and reload - How do I glue it all together? |
| Message-ID | <ec8466e1-7d98-4750-bc1a-c1c11e0d7c2a@googlegroups.com> |
I have a webpage, on which the content displayed depends on a parameter passed to or obtained by the webpage. This might be a $_GET variable, a $_SESSION variable or a cookie. I don't mind which is used. (I am open to suggestions as to which is the best method. I think $_SESSION.) When the page is initially displayed, the parameter is unset. On said page, there is to be a button, which when clicked, will increment the parameter and reload the page. Obviously, the parameter has to have the new value, so the reload causes the page contents to change. This ooperation might be repeated ad-nausem. Most of the indivual pieces of this (getting the paramter, and having the button reload the page) I can do, but I'm having trouble glueing it all together. I've managed to increment the parameter when the button is pressed, but only by calling an external form tag handler. If I do this, I can't get the page to reload. By what mechanism, can I have the button increment the parameter and cause the page reload? I hope this make sense; the old grey matter is addled today! Thanks in advance. Martin
[toc] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2012-08-03 16:23 +0100 |
| Message-ID | <jvgqcm$ov8$1@news.albasani.net> |
| In reply to | #6713 |
mwoolley wrote: > I have a webpage, on which the content displayed depends on a parameter passed to or obtained by the webpage. This might be a $_GET variable, a $_SESSION variable or a cookie. I don't mind which is used. (I am open to suggestions as to which is the best method. I think $_SESSION.) When the page is initially displayed, the parameter is unset. > > On said page, there is to be a button, which when clicked, will increment the parameter and reload the page. Obviously, the parameter has to have the new value, so the reload causes the page contents to change. This ooperation might be repeated ad-nausem. > > Most of the indivual pieces of this (getting the paramter, and having the button reload the page) I can do, but I'm having trouble glueing it all together. I've managed to increment the parameter when the button is pressed, but only by calling an external form tag handler. If I do this, I can't get the page to reload. > > By what mechanism, can I have the button increment the parameter and cause the page reload? > By making the button perform a submit action - either becuse its a submit button, or its a url button that calls the page with a parameter set as a GET or because its hooked to javsacript that causes a submit and sets parameters on the way. In general your PHP code should be of the form IF (page is to be displayed as a result of a submit action ) THEN (update any persistent data like a database with the users entry data contained in the POST variables) (get the parameters and make up the display according to what they are ) ELSE (display an initial page reflecting no user input yet) ($SESSION is a use of cookies by the way. Its just cookies wrapped in a simple API.) The only way you can do this without a submit action is to downland ALL the possible screen options in e.g. a javascript array and display the selection you want depending on buttons hooked to javascript functions. You would typically do that if you wanted to give the user something like an online calculator or some similar app. Whereas posting data and reloading the page is more appropriate as a forms front end to a database for example. You can mix the two, but it gets complicated. I have done that to create huge menu systems reflecting a hierarchy of parts in a stock database. ALL the parts are downloaded and they are only revealed when the user navigates a selection of drop down menus. > I hope this make sense; the old grey matter is addled today! > > Thanks in advance. > Martin -- To people who know nothing, anything is possible. To people who know too much, it is a sad fact that they know how little is really possible - and how hard it is to achieve it.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-08-03 11:35 -0400 |
| Message-ID | <jvgr55$ja9$1@dont-email.me> |
| In reply to | #6714 |
On 8/3/2012 11:23 AM, The Natural Philosopher wrote: <snip> > > > ($SESSION is a use of cookies by the way. Its just cookies wrapped in a > simple API.) > Completely INCORRECT! > > >> I hope this make sense; the old grey matter is addled today! >> >> Thanks in advance. >> Martin > > -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-08-03 11:50 -0400 |
| Message-ID | <jvgrvt$ofu$1@dont-email.me> |
| In reply to | #6713 |
On 8/3/2012 10:29 AM, mwoolley wrote: > I have a webpage, on which the content displayed depends on a parameter passed to or obtained by the webpage. This might be a $_GET variable, a $_SESSION variable or a cookie. I don't mind which is used. (I am open to suggestions as to which is the best method. I think $_SESSION.) When the page is initially displayed, the parameter is unset. > > On said page, there is to be a button, which when clicked, will increment the parameter and reload the page. Obviously, the parameter has to have the new value, so the reload causes the page contents to change. This ooperation might be repeated ad-nausem. > > Most of the indivual pieces of this (getting the paramter, and having the button reload the page) I can do, but I'm having trouble glueing it all together. I've managed to increment the parameter when the button is pressed, but only by calling an external form tag handler. If I do this, I can't get the page to reload. > > By what mechanism, can I have the button increment the parameter and cause the page reload? > > I hope this make sense; the old grey matter is addled today! > > Thanks in advance. > Martin > OK, let's start from the top. Since you want to display new content, you must make some type of request to the server (a good thing, since PHP is server-side :) ). There are a couple of ways to do this. The easiest is to put your button in a form and make it a submit button. Then the request will go to the server for processing. You could also use something like AJAX, but that seems a bit of overkill for something so simple. As to the variable you want to increment - you're correct, you can keep it several places. Where you keep it is pretty much dependent on how secure you want it. For instance, if it's a page number of a catalog, the user might want to be able to bookmark this particular page. In that case I would submit the form with method=GET with the value in the form (hidden or displayed field - whichever you want). This way when the user clicks the button the new page number will appear in the URL for easy bookmarking. OTOH, if you don't want them to be able to go to that page but have to always start from the beginning (but otherwise security is not important), you could use method=POST in your form. This way the page number wouldn't show up in the url (but is still in a field on the page). Finally, if security is a concern to you, then you shouldn't even pass the value in the form (values passed in $_POST can be easily spoofed). In this case you should use the $_SESSION variable and not even pass the value to the client. That way the request can't be spoofed. But the problem here is if the user has two tabs open to your site, the will share the same value. With GET or POST and the value in the page, each tab would contain it's own value, so they would be separate. There are ways around this restriction, but I'll not go into them here and potentially confuse you even more. In any of the above cases, it's then a simple matter to retrieve the value from the $_GET, $_POST or $_SESSION array, as applicable. Increment the value, and for $_GET or $_POST, place it back in the form. For $_SESSION, just incrementing the value in the $_SESSION array is fine. Determine what you want to display with the new value and send it back to the client. A bit long but I hope this helps. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Michael Vilain <vilain@NOspamcop.net> |
|---|---|
| Date | 2012-08-03 23:00 -0700 |
| Message-ID | <vilain-BFED6A.23000303082012@news.individual.net> |
| In reply to | #6713 |
In article <ec8466e1-7d98-4750-bc1a-c1c11e0d7c2a@googlegroups.com>, mwoolley <trogoz2012@gmail.com> wrote: > I have a webpage, on which the content displayed depends on a parameter > passed to or obtained by the webpage. This might be a $_GET variable, a > $_SESSION variable or a cookie. I don't mind which is used. (I am open to > suggestions as to which is the best method. I think $_SESSION.) When the > page is initially displayed, the parameter is unset. > > On said page, there is to be a button, which when clicked, will increment the > parameter and reload the page. Obviously, the parameter has to have the new > value, so the reload causes the page contents to change. This ooperation > might be repeated ad-nausem. > > Most of the indivual pieces of this (getting the paramter, and having the > button reload the page) I can do, but I'm having trouble glueing it all > together. I've managed to increment the parameter when the button is > pressed, but only by calling an external form tag handler. If I do this, I > can't get the page to reload. > > By what mechanism, can I have the button increment the parameter and cause > the page reload? > > I hope this make sense; the old grey matter is addled today! > > Thanks in advance. > Martin So the logic of the php script, as I understand it is script is called without any sort of argument in the URL and generates a page. The value for the variable is obtained through a $SESSION variable or some default. A form with a button is displayed, possibly with a number showing the value of the autoincrement variable. Click on the button, which must be part of a form. The form submits the page using the script $_SERVER['PHP_SELF'], passing the autoincremented variable as a $_GET variable. The resulting page displays, determines that $_GET[variable] is set, and uses that value rather than the session I don't see how reloading the page comes into this. When you click the <button>, that should submit the form and redraw the page. a <button> tag That's usually used for "hands off" automatic reloading. If this isn't part of the logic you're trying to accomplish, correct me where I don't have it right. -- DeeDee, don't press that button! DeeDee! NO! Dee... [I filter all Goggle Groups posts, so any reply may be automatically ignored]
[toc] | [prev] | [next] | [standalone]
| From | mwoolley <trogoz2012@gmail.com> |
|---|---|
| Date | 2012-08-06 05:47 -0700 |
| Message-ID | <4f960174-4043-459d-8626-e4ef6884d781@googlegroups.com> |
| In reply to | #6713 |
Brilliant replies! Thanks for all your help! I managed to get it all to work by creating the button (two actually) with this code
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="image" name="fbb" value="1" src="cal-bck.png" alt="bck" />
<input type="image" name="fbf" value="1" src="cal-fwd.png" alt="fwd" />
</form>
and the magic to see which button was pressed, and take appropriate action
if (isset($_POST['fbb']) or isset($_POST['fbb_x'])) {
build the backwards
} else {
if (isset($_POST['fbf']) or isset($_POST['fbf_x'])) {
build the forwards
}
}
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2012-08-06 16:59 +0000 |
| Message-ID | <jvot5m$3j8$1@dont-email.me> |
| In reply to | #6729 |
On Mon, 06 Aug 2012 05:47:44 -0700, mwoolley wrote:
> if (isset($_POST['fbb']) or isset($_POST['fbb_x'])) {
> build the backwards
> } else {
> if (isset($_POST['fbf']) or isset($_POST['fbf_x'])) {
> build the forwards
> }
> }
Suggestion:
if ( forwards_condition ) {
do the forwards thing
}
elseif ( backwards_condition ) {
do the backwards thing
}
else {
do the nothing thing
}
You don't need to use an if inside the else, elseif (or else if) allows
you to split a decision more than two ways without nesting if statements,
and in this case would be more logical.
Rgds
Denis McMahon
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web