greymoose has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
I've got a form created by a cgi script (sorry, I'm one of those who discovered Perl through cgi). When someone clicks on a button on the form another script is supposed to read the data from the button and a hidden input and write them to cookies. It works fine in Firefox, Galeon loves it, IE doesn't want to know about it.
I'm pretty sure the problem is that the cookie isn't being set because it isn't picking up the cookie value in the next script. I've tried using CGI::Cookie but wound up with the same results.
I've gone back to my original code to try and sort this out. Here it is:
Set the cookies and redirect:
# Process form and set cookies my ($cat) = param('butCat'); my ($typ) = param('txtTyp'); my ($to_set) = cookie(-name => 'cat', -value => $cat, -path => '/', ); my ($to_set_a) = cookie(-name => 'bus_com', -value => $typ, -path => '/', ); my $cgi = CGI->new(); print $cgi->redirect(-uri => '/'.$typ.'sub.html', -cookie => [$to_ +set, $to_set_a]);
Get the cookie in the next script:
# Get Subcat data from cat cookie $catnum = cookie('cat');
To see it in action (or not) go to www.martoncentral.co.nz/buslst.html and click on any of the sub category buttons towards the top of the page. Thanks in advance for sharing your wisdom.

Replies are listed 'Best First'.
Re: IE not setting or retireving cookies
by dorward (Curate) on Nov 13, 2006 at 10:21 UTC

    It is hard to say for sure without seeing the script, and I'm not entirely sure which set of buttons you mean, but I suspect the issue is this:

    <button name='butCat' class='clear' value='0012'><b>Accomodation</b></button>

    A bug in Internet Explorer (including version 7) causes it to submit the display value ("Accomodation"), not the value attribute value ("0012"), for button elements.

    Since you seem to be using the value of butCat for something, this is likely your problem.

    (Another problem you have is a huge number of syntax errors in your markup, I strongly suggest a visit to the validator with an HTML 4.01 Strict Doctype.)

      Thanks dorward, I'm not getting any value at all into the cookie so I'm not sure that this bug will be the cause of this problem.
      As for the validator. Well, (embarassed grin) I finally started putting my pages through it when I discovered this problem and, yup, I've got alot to fix.
        Ok, that bug was causing me problems - thanks for the heads up or I would have been there for even more hours.
Re: IE not setting or retireving cookies
by themage (Friar) on Nov 13, 2006 at 12:52 UTC
    Experience told me that IE don't like Set-Cookie: and Location: in the same header.

    The way I found to bypass this particular problem was making the redirect in javascript if the browser was IE.

    You can do that with this html:
    <html><body> <script>window.location='/thenewurl';</script> </body></html>
    It's not the perfect solution I would like to use, but it works. It's too bad that some software that renders HTML shouldn't be called browser.

      I'm not sure what I did here but when I tried this I got an Error 500 from the server. Thanks for the thought though.
Re: IE not setting or retireving cookies
by f00li5h (Chaplain) on Nov 13, 2006 at 08:52 UTC

    Well, IE 6.0 does what you say (or doesn't) and Opera doesn't do what you say (but what you want)

    perhaps it's to do with the path you're seting it for IE has an issue with it's Content Advisor/Rathing thingy, that sometimes plays tricks on you (by making extra requests, that may reset the cookies)

    i'm sure there are about 100 other IE bugs that munch cookies, but this was the one that came to mind ...

    Perhaps you can pass your categories as GET's or have them as directores (or look like directories with tricks involving $ENV{PATH_INFO})

    HTH

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;
      Hi f00li5h, Thanks for that comment.I'm thinking you may be right about using get instead of cookies. I may have bitten off more than I can chew at this point (pun intended).
      The catch is that I skipped over that bit of the tutorial when I was learning about forms and I can't find anything to learn about capturing the data from. Do you have any suggestions?
      Cheers,

        Well, the smart money is on use CGI and call the param method.

        Odds are that you'll eventually have had enough of usign that for more complicated forms and you'll want CGI::FormBuilder

        There are many good CGI tutorials out there, and even the bad ones are worth reading (if only once)

        In other news $ENV{PATH_INFO} will give you all the extra stuff in the url, after your script name, so if your script is host/foo.pl, and the request is made for http://host/foo.pl/clothes/shirt/hawiian, `clothes/shirt/hawiian' will appear in $ENV{PATH_INFO} and you simply feed that to a split '/' or some more complicated sub somewhere to map that extra string to some content that matches. (sadly, I don't have a pre-wrapped nugget-o-code to show off with, although i'd love to)

        merlyn also has some wicked-mad articlesl on stonehenge that you may be interested in oggling the now-defunct WebTechniques Magazine. - the Magazine is defunct, not the info therein.

        @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

        In other news, Ovid wrote a failry security focused CGI tutorial that you may want to read over

        @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;
Re: IE not setting or retireving cookies
by derby (Abbot) on Nov 13, 2006 at 13:11 UTC

    Hmmm .... it may be silly, but what happens when you reverse the params?

    print $cgi->redirect( -cookie => [$to_set, $to_set_a], -uri => '/'.$typ.'sub.html' );

    -derby
      In my short experience with programming nothing is silly.
      Unfortunately nothing happened.