Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Button to Set PHP Session Value

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
On a PHP form with a pair of radio buttons, I need the radio selection to be able to add a value to the existing PHP session when selected but before the form is submitted. I know PHP fairly well but I know little (virtually nothing) about JavaScript. Can anyone help?

Don
contact@pc-homepage.com
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
I know very little about php, but I do know asp. Both are server-side scripts. Therefore, you cannot respond to client-side events. What that means to you is that you cannot change a server-side session variable based on a client-side action until the server is called again (usually by a form submission). Sorry.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
What I am trying to do is to simply "respond" to the HTML without actually submitting anything (using onclick or whatever), not to the PHP script. But you're right, the session would be on the server and inaccessable to the client JavaScript. I forgot about that but thanks anyway for reminding me.

Don
contact@pc-homepage.com
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
It occurred to me that this can also be done using a client Cookie but again, I have no idea how to do it. That is, I know how to do it in PHP but not in JavaScript and since this form is submitting off-site, I cannot use either a Session or a Cookie in the PHP because the PHP code is not receiving any input.

The page has many forms, each the same except that some have the radio buttons (it is looping through items in a database and each needs its own separate form). The radio buttons all have the same names and values because they are on individual forms, and each of those with it has two.

If JavaScript could be added so that clicking one radio button makes the rest change, and a Cookie is set at the same time as to the choice, I can incorporate it into the PHP code and the same Cookie can be used by two other pages' forms. Any help will be greatly appreciated.

Don
contact@pc-homepage.com
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Here's an idea: You can use PHP to add a javascript (to the returning page) that sets a javascript var equal to your session, then using that javascript var to add/subtract/whatever -client side.

What is it, in short, you want to do?

Cheers,


Jakob
 
As I understand it, you are suggesting that the page be submitted, the session grabbed by PHP and returned, then used that way on the client. Assuming I knew how to write one in JavaScript (I don't), if the PHP script were submitting to my own site or to something for which I have control, I could do this (I would do it all in PHP in that case), but it is not. It is submitting completely off-site and the returning page is someone else's.

But it doesn't have to be done as a session when a cookie will work just as well. If clicking a radio button can set a cookie using JavaScript, I can retrieve the cookie in PHP and do it that way, and even create a session from the cookie. Similarly, if selecting a single radio button on a page with several such forms can change them all to the new choice AND set the cookie, it would be ideal.

Thanks for any help!

Don
contact@pc-homepage.com
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Don,

I don't work with cookies, but I found a FAQ in here -maybe it can give you what you need...?!

faq216-1956

Good Luck §;O)


Jakob
 
Thanks, I'll look to see if I can make sense of it and try to figure out how to incorporate some kind of trigger in the radio button. Just to be clear in case it makes a difference, I need to set or reset only a single cookie, not multiple ones as the FAQ describes. My page has multiple forms but those with the radio buttons are the same (same name and value for the radio buttons and form) so one cookie will do the trick.

Don
contact@pc-homepage.com
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top