korsohill Posted May 26, 2009 Share Posted May 26, 2009 Can I make a webpage log into one of two differet areas with radio buttons?For example, I'm making a page that will easily log me in to check my grades at school, however, they have two different addresses, one that works only at school and one that works anywhere else. Can I use radio buttons to choose between "School" and "Home"? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 26, 2009 Share Posted May 26, 2009 Yes, you can submit a radio button with a form and check the value of it. Link to comment Share on other sites More sharing options...
korsohill Posted May 26, 2009 Author Share Posted May 26, 2009 Ok, how is the done then? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 26, 2009 Share Posted May 26, 2009 It's the same thing as with any other form element. You give all radio buttons the same name and different values, like you normally set up radio buttons, and when it gets submitted you'll find the value they chose in $_POST under the name that you used for the radio group. Link to comment Share on other sites More sharing options...
korsohill Posted May 26, 2009 Author Share Posted May 26, 2009 My page isn't submitting to a page that I have control of. If that will still work, please expand on it. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 26, 2009 Share Posted May 26, 2009 That won't work, the code to change is on the form processing page. Link to comment Share on other sites More sharing options...
korsohill Posted May 26, 2009 Author Share Posted May 26, 2009 Then can I make a script to log into another site?Or can it work a different way? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 27, 2009 Share Posted May 27, 2009 It depends how the other site logs in. If you're just submitting a username and password then you can set the action of the form to the other site, whichever page they have that processes the login form, and make sure that your input names are the same as what they expect. Basically, you only have to send them the same information that they get from their own login form. PHP cannot log you in to another site, if you use PHP to send a login request to a remote server, it's going to start a session for the PHP server, not your browser. If you need to dynamically change the action on a form before you submit it then you would use Javascript for that. Link to comment Share on other sites More sharing options...
korsohill Posted May 27, 2009 Author Share Posted May 27, 2009 Ok, then what Javascript could I use to have multiple form actions? I've never used JS. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 27, 2009 Share Posted May 27, 2009 You'll want to get started going through the Javascript tutorials. In broad terms, you'll need a click event on each radio button, so the attribute to use would be onclick for each button. The click event handler needs to be a function that just sets the action of the form with the value on the radio button. In order to do that, you need to give the form an ID. Inside the function, you would use document.getElementById to get the form object. I think that form objects have an action property, so you would just set the action property of the form object to the value of the radio button (assuming that you're storing the various URLs as the values of the radio buttons). If you need to replace the entire form when you click the radio button, like if each site has a different set of login fields, it's a lot more complicated. Link to comment Share on other sites More sharing options...
korsohill Posted May 27, 2009 Author Share Posted May 27, 2009 Well I have done this with two submit buttons, but for some reason, because the script uses cookies, it doesn't work properly. Link to comment Share on other sites More sharing options...
korsohill Posted May 27, 2009 Author Share Posted May 27, 2009 Ah, I've gone as far as I can go now...I need to be able to see the source PHP to do anything more! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.