[PHP] Remembering which option in a SELECT tag the user had chosen
Hi, I have a SELECT on a web form. Friday August 22, 04:00 PM - 06:00 PM Friday August 22, 06:00 PM - 08:00 PM Friday August 22, 08:00 PM - 10:00 PM Friday August 22, 10:00 PM - 12:00 AM Saturday August 23, 12:00 AM - 02:00 AM Saturday August 23, 12:00 PM - 02:00 PM Saturday August 23, 02:00 PM - 04:00 PM Saturday August 23, 04:00 PM - 06:00 PM Saturday August 23, 06:00 PM - 08:00 PM Saturday August 23, 08:00 PM - 10:00 PM Saturday August 23, 10:00 PM - 12:00 AM Sunday August 24, 12:00 AM - 02:00 AM Sunday August 24, 12:00 PM - 02:00 PM Sunday August 24, 02:00 PM - 04:00 PM Only one option may be chosen When I submit this form, there could be errors. When I have errors, I wish to reprint the form with the user's values remembered. In the reprinted SELECT tag, one of the OPTION tags will now have a SELECTED attribute. Is there any elegant way to insert the SELECTED attribute on the right option? Thanks, Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Remembering which option in a SELECT tag the user had chosen
Hi John, I was thinking of inserting a check on each option, but I thought there had to be a different way. I've received ideas of storing the option values in an array and creating a function to generate that dropdown by grabbing values out of the array, so I want to go with that because that is more elegant, which what I was after. Thanks! --Stephen Unless you come up with a nice function to create this box for you, then the only way is to go in on each line, in each tag and check $_POST['TimeChoice'] (or $_GET, $_REQUEST, whatever...) to see if it equals the current value. if($_POST['TimeChoice']=="Friday August 22, 04:00 PM - 06:00 PM") { echo " SELECTED"; }?>>Friday August 22, 04:00 PM - 06:00 PM ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] if (a == b) ...
Hi, I have a conditional: if (a == b) a is the number 0, but b is a string "Friday August 22". The condition is evaluating as true, which is not what I want. What am I misunderstanding? Thanks, Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if (a == b) ...
Cal, Thanks for the suggestion. I looked up equality on www.php.net, and there are many comments about how == works. I also found out === works too, or is that still lazy? Thanks, Stephen Cal Evans wrote: Stephen, "Friday August 22" evaluates to the number 0. (check the docs for intval()) Therefore the condition would be true. I stated in an earlier thread this week. It is bad for to allow PHP todo your conversions for you. At the least it's lazy, at the most it will cause unpredictable results. (as is your case below.) If you really MUST compare a string and a number, do an explicit cast first. if ($a==intval("Friday August 22")) or if (strval($a)=="Friday August 22") In both cases above, since we are explicitly casting, it is easy to predict the results and explain them. (In the above, the first should be true and the second should be false.) =C= * * Cal Evans * Stay plugged into your audience. * http://www.christianperformer.com * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checking the season
Hi, Just need a sounding board to help me think this through. I want to check the current date to determine what "season" it is and display the appropriate picture. I define spring as 03/21/, summer as 06/21/, autumn as 09/21/, and winter as 12/21/. I form a string for the current date and get a timestamp via mktime(). I also get the equivalent timestamps for the dates above for the seasonal changes. Then, I compare the current date to see if it's between the seasonal dates. The problem is when I go from 12/31/ to 01/01/(+1). Since winter and spring dates are one year apart, the current date timestamp comparison gets messed up and nothing displays. How do I do a proper comparison? I was thinking of just seeing if the current date timestamp is greater than each of the seasonal date timestamp, but it feels like I would miss something. Would I? Or is there another solution? Thank you for your time. --Stephen
Re: [PHP] Checking the season
I'll have to use and if/elseif construct, because I don't believe a switch() constructs cases can take expressions, can it? - Original Message - From: "Bogdan Stancescu" <[EMAIL PROTECTED]> To: "webapprentice" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Saturday, January 05, 2002 11:38 AM Subject: Re: [PHP] Checking the season > You could do a case() or if/elseif, check if it's spring, summer or autumn and leave the code for winter as default/else. > > Bogdan > > webapprentice wrote: > > > Hi, > > Just need a sounding board to help me think this through. > > > > I want to check the current date to determine what "season" it is and display the appropriate picture. > > > > I define spring as 03/21/, summer as 06/21/, autumn as 09/21/, and winter as 12/21/. > > > > I form a string for the current date and get a timestamp via mktime(). > > I also get the equivalent timestamps for the dates above for the seasonal changes. > > > > Then, I compare the current date to see if it's between the seasonal dates. > > The problem is when I go from 12/31/ to 01/01/(+1). > > Since winter and spring dates are one year apart, the current date timestamp comparison gets messed up and nothing displays. > > > > How do I do a proper comparison? I was thinking of just seeing if the current date timestamp is greater than each of the seasonal date timestamp, but it feels like I would miss something. Would I? Or is there another solution? > > > > Thank you for your time. > > > > --Stephen > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Checking the season
Thanks for the code snippet. I see that everybody defaults to a season. I was doing a && comparison between two seasons, so that's why it messed up when it into the new year. Thanks to Bogdan and Tom for the helpers. I can go debug my code. And make it less complicated. ^_^;;; (It's was a lot longer than what is here.) - Original Message - From: "Tom Rogers" <[EMAIL PROTECTED]> To: "webapprentice" <[EMAIL PROTECTED]>; "Bogdan Stancescu" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Saturday, January 05, 2002 11:17 PM Subject: Re: [PHP] Checking the season > Hi > This should work: > $year = date("Y"); > $spring = mktime (0,0,0,3,21,$year); > $summer = mktime (0,0,0,6,21,$year); > $autumn = mktime (0,0,0,9,21,$year); > $winter = mktime (0,0,0,12,21,$year); > $now = mktime(); > if($now < $spring || $now >= $winter): > echo "Winter"; > elseif($now >= $autumn): > echo "Autumn"; > elseif($now >= $summer): > echo "Summer"; > else: > echo "Spring"; > endif; > ?> > BTW There may be a bug in mktime() (php4) if you use 08 or 09 in the > month part...on my system this happens > (linux/apache/php4.1) > > $autumn = mktime (0,0,0,09,21,2002); > echo "date = ".date("d/m/Y",$autumn).""; > ?> > > This prints: date = 21/12/2001 > > Also prints the same date for a month of 08 > > Tom > > > > At 11:34 AM 6/01/02, webapprentice wrote: > >I'll have to use and if/elseif construct, because I don't believe a switch() > >constructs cases can take expressions, can it? > > > > > >- Original Message - > >From: "Bogdan Stancescu" <[EMAIL PROTECTED]> > >To: "webapprentice" <[EMAIL PROTECTED]> > >Cc: <[EMAIL PROTECTED]> > >Sent: Saturday, January 05, 2002 11:38 AM > >Subject: Re: [PHP] Checking the season > > > > > > > You could do a case() or if/elseif, check if it's spring, summer or autumn > >and leave the code for winter as default/else. > > > > > > Bogdan > > > > > > webapprentice wrote: > > > > > > > Hi, > > > > Just need a sounding board to help me think this through. > > > > > > > > I want to check the current date to determine what "season" it is and > >display the appropriate picture. > > > > > > > > I define spring as 03/21/, summer as 06/21/, autumn as > >09/21/, and winter as 12/21/. > > > > > > > > I form a string for the current date and get a timestamp via mktime(). > > > > I also get the equivalent timestamps for the dates above for the > >seasonal changes. > > > > > > > > Then, I compare the current date to see if it's between the seasonal > >dates. > > > > The problem is when I go from 12/31/ to 01/01/(+1). > > > > Since winter and spring dates are one year apart, the current date > >timestamp comparison gets messed up and nothing displays. > > > > > > > > How do I do a proper comparison? I was thinking of just seeing if the > >current date timestamp is greater than each of the seasonal date timestamp, > >but it feels like I would miss something. Would I? Or is there another > >solution? > > > > > > > > Thank you for your time. > > > > > > > > --Stephen > > > > > > > > > > > >-- > >PHP General Mailing List (http://www.php.net/) > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > >To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Variables within a string
Hello, When I try to do this: $foo = "Entry for for $HTTP_POST_VARS[\"name\"]"; I receive this error: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' on line X Why does it do this, and how do I get around this, besides assigning the value of $HTTP_POST_VARS[\"name\"] to variable $bar? Thank you for your time and help. --Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Variables within a string
Oh, so that's how you deal with indexed variables inside of double quotes... I can't believe that has eluded me for so long... --- From: Jason Wong <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Date: Mon, 11 Mar 2002 12:09:15 +0800 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: Re: [PHP] Variables within a string On Monday 11 March 2002 11:10, Chris Cocuzzo wrote: > I would imagine the problem has something to do with those escaped quote > marks, but in any case, you could probably get around it by doing this: > > $foo = "Entry for " . $HTTP_POST_VARS["name"]; > > some correct me if I'm wrong Or simply: $foo = "Entry for for $HTTP_POST_VARS[name]"; -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* If you don't have a nasty obituary you probably didn't matter. -- Freeman Dyson */
[PHP] Double quotes in form fields and submitting them
Hi, I have a form with a text field, say userName. I put a value in that has double quotes (i.e. "foobar") and submit this form. On output I have this: The output ends up being a \. How do I keep the double quotes? Thanks, Stephen
Re: [PHP] Double quotes in form fields and submitting them
Hi, "foobar" becomes simply \ I've lost foobar AND the double quotes. Is there a way to keep them all? --Stephen - Original Message - From: "Miguel Cruz" <[EMAIL PROTECTED]> To: "webapprentice" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Saturday, March 23, 2002 7:49 PM Subject: Re: [PHP] Double quotes in form fields and submitting them > On Fri, 22 Mar 2002, webapprentice wrote: > > I have a form with a text field, say userName. > > I put a value in that has double quotes (i.e. "foobar") and submit this form. > > > > On output I have this: > > > > > > The output ends up being a \. > > The quotes go away, or they just get a backslash before them? If the > latter, try > > miguel > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] The infamous HTML quotes Re: [PHP] Double quotes in form fields and submitting them
Sorry Miguel, it's the HTML entities nonsense again. It displayed as \ on my browser, but the HTML source code indicated otherwise. Thus, if I entered "foobar", it shows up as \ but the HTML source shows. So value="\" was the culprit, so you're original solution was in the right direction. stripslashes() itself wouldn't work because the HTML source would be value=""foobar"" and on in HTML, only the first two double quotes count. The solution was this, which apparently has been discussed many times before. stripslashes(htmlentities($HTTP_POST_VARS["realName"])); or stripslashes(htmlspecialcharacters($HTTP_POST_VARS["realName"])); Thanks for your help in leading me to the right direction. - Original Message - From: "Miguel Cruz" <[EMAIL PROTECTED]> To: "webapprentice" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Saturday, March 23, 2002 8:03 PM Subject: Re: [PHP] Double quotes in form fields and submitting them > That's a little odd; something else must be going on. Can you provide some > more code, and, preferably, a pointer to a live example? > > miguel > > On Sat, 23 Mar 2002, webapprentice wrote: > > > Hi, > > "foobar" becomes simply \ > > > > I've lost foobar AND the double quotes. Is there a way to keep them all? > > > > --Stephen > > > > - Original Message - > > From: "Miguel Cruz" <[EMAIL PROTECTED]> > > To: "webapprentice" <[EMAIL PROTECTED]> > > Cc: <[EMAIL PROTECTED]> > > Sent: Saturday, March 23, 2002 7:49 PM > > Subject: Re: [PHP] Double quotes in form fields and submitting them > > > > > > > On Fri, 22 Mar 2002, webapprentice wrote: > > > > I have a form with a text field, say userName. > > > > I put a value in that has double quotes (i.e. "foobar") and submit this > > form. > > > > > > > > On output I have this: > > > > > > > > > > > > The output ends up being a \. > > > > > > The quotes go away, or they just get a backslash before them? If the > > > latter, try > > > > > > miguel > > > > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Any PHP equivalent of Macromedia ColdFusion's location tag?
Is there any PHP function that works like ColdFusion's location tag? After a certain execution, I wish to leave the current PHP page entirely and go to another page. Is this possible? I'm scouring the help stuff and am still digging for answers. Thanks.
Re: [PHP] Any PHP equivalent of Macromedia ColdFusion's location tag?
Hi, Thanks for the reply. I saw this as well in the mailing list archives, but everyone is saying you cannot output ANYTHING before calling header. Unfortunately, I'm calling this at the end of a process, so it won't work. It tells me I've already sent out header information. I've basically created a single PHP page with a form. When the form is submitted, it submits to itself. It checks if the form is submitted, and then goes to mail the contents to someone. After mailing, I want to go to a Thank You page. I want to get away from this PHP page, because I don't want a person refreshing the page and causing the PHP page to submit again. Thus, is there something else I can do? Or am I just not seeing this? Thanks, Stephen - Original Message - From: "James" <[EMAIL PROTECTED]> To: "webapprentice" <[EMAIL PROTECTED]> Sent: Tuesday, March 26, 2002 10:20 PM Subject: Re: [PHP] Any PHP equivalent of Macromedia ColdFusion's location tag? > header("Location: http://www.google.com";); > replace that url with the page you want it to go to > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Any PHP equivalent of Macromedia ColdFusion's location tag?
Hi Mr. Lerdorf, I look forward to you upcoming O'Reilly PHP book. =) Yes, a META tag refresh or Javascript control seems to be the only way left. Strange that URL redirection is so unusual to implement in PHP compared to ASP or Coldfusion (unless they do something klunky under the hood). Anyway, I also noticed that when the manual says you cannot output ANYTHING, I found out that if I close out all my spaces in the PHP page by tightening the php container tags, I will not output anything first. I forgot that even whitespace would be considered a web page and would generate http headers (since the PHP processor probably translates whitespace as echo/print statements). Thanks. --Stephen - Original Message - From: "Rasmus Lerdorf" <[EMAIL PROTECTED]> To: "webapprentice" <[EMAIL PROTECTED]> Cc: "James" <[EMAIL PROTECTED]>; "Jason Murray" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, March 27, 2002 12:01 AM Subject: Re: [PHP] Any PHP equivalent of Macromedia ColdFusion's location tag? > So use a Javascript meta-refresh > > On Wed, 27 Mar 2002, webapprentice wrote: > > > Hi, > > Thanks for the reply. I saw this as well in the mailing list archives, but > > everyone is saying you cannot output ANYTHING before calling header. > > > > Unfortunately, I'm calling this at the end of a process, so it won't work. > > It tells me I've already sent out header information. > > > > I've basically created a single PHP page with a form. When the form is > > submitted, it submits to itself. It checks if the form is submitted, and > > then goes to mail the contents to someone. After mailing, I want to go to a > > Thank You page. I want to get away from this PHP page, because I don't want > > a person refreshing the page and causing the PHP page to submit again. > > > > Thus, is there something else I can do? Or am I just not seeing this? > > > > Thanks, > > Stephen > > > > > > > > > > - Original Message - > > From: "James" <[EMAIL PROTECTED]> > > To: "webapprentice" <[EMAIL PROTECTED]> > > Sent: Tuesday, March 26, 2002 10:20 PM > > Subject: Re: [PHP] Any PHP equivalent of Macromedia ColdFusion's location > > tag? > > > > > > > header("Location: http://www.google.com";); > > > replace that url with the page you want it to go to > > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Any PHP equivalent of Macromedia ColdFusion's location tag?
I now recall that ColdFusion's location tag accepts no data parameters, so you can't pass data to it. It is essentially a redirect. Thus, it may be doing an HTTP header location under the hood. In ColdFusion, I may have logic like so: - OK! I don't get any errors, so I think it buffers the entire output first and then throws away if it determines if it needs to go elsewhere. In PHP, it would look something like this: This will not run, because of the whitespace. I presume PHP immediately begins the http/html stream as soon as it sees non-php code. In ColdFusion, it doesn't care about the whitespace. In PHP, it does care about the whitespace. That is what I discovered in my original problem. I had a whitespace between the php identifiers. I simply closed off the whitespace, and I was fine. Thanks for clarifying all this. Sincerely, Stephen - Original Message - From: "Rasmus Lerdorf" <[EMAIL PROTECTED]> To: "webapprentice" <[EMAIL PROTECTED]> Cc: "James" <[EMAIL PROTECTED]>; "Jason Murray" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, March 27, 2002 12:24 AM Subject: Re: [PHP] Any PHP equivalent of Macromedia ColdFusion's location tag? > > Hi Mr. Lerdorf, > > I look forward to you upcoming O'Reilly PHP book. =) > > > > Yes, a META tag refresh or Javascript control seems to be the only way left. > > Strange that URL redirection is so unusual to implement in PHP compared to > > ASP or Coldfusion (unless they do something klunky under the hood). > > They do. There is no magic here. If you want output on a page and also do > a redirect, the only way to do it is with a javascript meta-refresh (well, > you can do some tricks with frames as well, but I lump those tricks under > Javascript redirects). I don't care what ASP of Cold Fusion tells you, if > they allow you to send some data for the page and then redirect, then they > are either doing a Javascript meta-refresh or simply tossing your data and > doing a Location redirect. > > If you have no output, then you can use a Location redirect. What ASP and > Cond Fusion might do is buffer your output and simply throw it away if you > then at some point do a Location redirect. That seems kind of silly to me > though. It seems like a mistake to me to just chuck away output data like > that. You can do that with PHP as well by turning on output buffering. > You can send all sorts of output after a Location redirect, but there will > be no browser around to see it because it has already received the > Location redirect and is off viewing the other page. > > > Anyway, I also noticed that when the manual says you cannot output ANYTHING, > > I found out that if I close out all my spaces in the PHP page by tightening > > the php container tags, I will not output anything first. I forgot that > > even whitespace would be considered a web page and would generate http > > headers (since the PHP processor probably translates whitespace as > > echo/print statements). > > Yup, a space is as valid a character as any other. > > -Rasmus > > PS. One of the things with PHP is that we have never gone out of our way > to hide the actual mechanics of HTTP very much from the users. I think it > is important for people to actually understand what is going on. That's > why we don't have a redirect() function but instead tell you to send an > HTTP header called Location. Because that is what needs to happen under > the covers. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php