SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Location
    NYC
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Radio Button Input Value Determines Which Form to Process

    Here is the scenario:

    I have a successful php-based login screen for users. There are two radio buttons the user can select.

    1) Login into Account Page (on my server).
    2) Login into Affiliated Page (not on my server -- another website).

    Now by default the radio button for the Account Page is selected. My question is, if the user selects the second radio button, how do I tell the form to now process the username/password for the affiliated site?

    Currently, the action attribute in the form tag is set to "process.php" when the first radio button, Account Page, is selected. No big deal there.

    But when they click the second radio button, I need the action attribute to process on the affiliated website by sending the username and password to this page: "http://www.affiliatepage.com/process.aspx"

    So the issue is how does the login page know which form action to take?

    Do I need to create two forms? If so, should the form for the Affiliate Page login be hidden?

    Here's some code ideas I have cooked up.

    The first is the HTML for the original form that processes as if the user wants to simply login to their account (on my server).

    Code HTML4Strict:
    <form name="login_form" action="process.php" method="POST">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <tr><td>Username:</td><td>
    <input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
     
    <tr><td>Password:</td><td>
    <input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
    <tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
    <font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp;</font>
     
    <tr>
    <td colspan="2" align="left">
     
    <input type="radio" name="group1" value="Account">
    <input type="radio" name="group1" value="Affiliate">
     
    <input type="hidden" name="sublogin" value="1">
    <input type="submit" value="Login"></td></tr>
     
     
     
    <tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
    <tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr>
    </table>
    </form>


    Now, here is a javascript function to see what the value of the radio button is :

    Code JavaScript:
    <script language="JavaScript"><!--
    function go(what) {
        for (var i=0;i<3;i++) {
            if (what.group1[i].checked) {
                document.forms[what.group1[i].value].submit();
            }
        }
    }
    //--></script>

    And some generic HTML to follow to get an idea of how this function would operate:


    Code HTML4Strict:
    <form action="process.php" target="targetframename" name="group1"><input type="hidden" value="Account"></form>
    <form action="http://www.affiliatepage.com/process.aspx" target="targetframename" name="group2"><input type="hidden" value="Affiliate"></form>
     
    <form>
    Login to Account Page<input type="radio" name="group1" value="Account">
    Login to Affiliate Page<input type="radio" name="group1" value="Affiliate">
    <input type="button" onClick="go(this.form)" value="Submit">
    </form>

    So overall, how would I implement the function and the generic type HTML that follows, into my current HTML? Is there a simpler way?

    Thanks for any and all help.

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,343
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Using an onsubmit action (which relies on Javascript being enabled), you can alter the 'action' field as an attribute of the form element.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Location
    NYC
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So do you mean something like this:

    Code HTML4Strict:
    <input type="button" onSubmit="how do I determine the action for the proper form?" value="Submit">

    ???

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's an example:
    Code:
    function setFormAction(frm) {
    	if (frm.group1.value == "Affiliate") {
    		frm.action = "http://www.affiliatepage.com/process.aspx";
    		frm.target = "targetframename";
    	}
    	return true;
    }
    
    
    <form method="post" action="process.php" onsubmit="return setFormAction(this);">
    	<!-- username and password inputs -->
    	
    	Login to Account Page<input type="radio" name="group1" value="Account" checked>
    	Login to Affiliate Page<input type="radio" name="group1" value="Affiliate">
    
    	<input type="submit" value="Go">
    </form>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •