Form processing: change the "action=" based on pull down menu

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Form processing: change the "action=" based on pull down menu

    Hi group -

    I have an html form for that uses username and password to login to a
    specific area of the website. The "area" the user wants to go to is
    based on a pull down menu. Becasue the user/password info is in
    differnet databases, how can I call different validation scripts based
    on this input ?
    THANK YOU!

    See below please. Somethinglike this:

    form.html:
    <form name="loginform" method="post" action="login.php">
    <select name="loginform">
    <option value="one">Section 1</option>
    <option value="two">Section 2</option>
    </select>

    login.php:

    @extract($_POST);
    if($_POST[loginform] == "one") {

    echo "action = /forums/scc/dispatch.cgi/_admin/AVFLogin"
    NAME="LoginForm" >
    echo "<input type=hidden name=\"autologin\" value=\"1\">\n";
    echo "<input type=hidden name=\"formstyle\" value=\"standard\">\n";
    echo "<input type=hidden name=\"returnforum\" value=\"_admin\">\n";
    echo "<input type=hidden name=\"returnmsg\"
    value=\"acahomepage\">\n";

    } else {

    echo "action = /path to different cgi \n";
    echo :different values for hidden fields".

    }
    Sylvie Stone Guest

  2. Similar Questions and Discussions

    1. Change user role from "Publisher" to "Administrator"
      Have three users on a particular website - all need to be "administrators". Two are listed as administrators (one of which is me), the third is...
    2. Anyway to "pull-in" data from a website?
      I'm using php/mysql. Is there anyway to have a page that will get the data from another webiste page? For example, I want to have a page that...
    3. #25366 [NEW]: form buttons of type "image" dont send "submit" $_POST variable in IE
      From: jordanolsommer at imap dot cc Operating system: Windows XP PHP version: 4.3.2 PHP Bug Type: Variables related Bug...
    4. "save", "selective color" menu go too slow. Please help!
      have intel pentium 4 cpu and photoshop 7. when im using "selective color" or "save" menu (im a novice of photoshop), i have to wait kind of long...
    5. "Start" "Program" "Menu" list is empty
      For what ever reason my list of installed programs in my "Start" "Programs" menu is empty. Anyone know how to restore the list. Thanks for your...
  3. #2

    Default Re: Form processing: change the "action=" based on pull down menu

    Sylvie Stone wrote:
    > Hi group -
    >
    > I have an html form for that uses username and password to login to a
    > specific area of the website. The "area" the user wants to go to is
    > based on a pull down menu. Becasue the user/password info is in
    > differnet databases, how can I call different validation scripts based
    > on this input ?
    > THANK YOU!
    Hi,

    This is actually a javascript trick you need.
    You can dynamically set the action of a form, just by assigning a new value
    to it.

    Try something like this:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
    <html>
    <head>
    <title>formactiontest</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="GENERATOR" content="Quanta Plus">

    <script language="javascript">

    function doSubmit(){
    // get the chosen option
    selind = document.forms.mydynamicform.selectaction.selected Index;
    // get the value
    selval = document.forms.mydynamicform.selectaction[selind].value;

    // now set this value as action for the form
    document.forms.mydynamicform.action=selval;

    // and submit
    document.forms.mydynamicform.submit();

    }

    </script>

    </head>
    <body>

    <form action="unknownyet" METHOD="POST" name="mydynamicform">

    Choose your action:
    <select name="selectaction">
    <option value="login1.php">go to login 1</option>
    <option value="login2.php">go to login 2</option>
    <option value="login3.php">go to login 3</option>
    </select>
    <br>
    Your name? <input type="text" name="yourname" size=10>
    <br>
    <input type="button" onClick="doSubmit()" value="Go!">

    </form>

    </body>
    </html>


    Regards,
    Erwin
    Erwin Moller Guest

  4. #3

    Default Re: Form processing: change the "action=" based on pull down menu

    [email]sylviestone@canada.com[/email] (Sylvie Stone) wrote in message
    news:<181a24a8.0309160650.45b744df@posting.google. com>...
    >
    > I have an html form for that uses username and password to login to a
    > specific area of the website. The "area" the user wants to go to is
    > based on a pull down menu. Becasue the user/password info is in
    > differnet databases, how can I call different validation scripts based
    > on this input ?
    > THANK YOU!
    >
    > See below please. Somethinglike this:
    >
    > form.html:
    > <form name="loginform" method="post" action="login.php">
    > <select name="loginform">
    > <option value="one">Section 1</option>
    > <option value="two">Section 2</option>
    > </select>
    >
    > login.php:
    >
    > @extract($_POST);
    > if($_POST[loginform] == "one") {
    >
    > echo "action = /forums/scc/dispatch.cgi/_admin/AVFLogin"
    > NAME="LoginForm" >
    > echo "<input type=hidden name=\"autologin\" value=\"1\">\n";
    > echo "<input type=hidden name=\"formstyle\" value=\"standard\">\n";
    > echo "<input type=hidden name=\"returnforum\" value=\"_admin\">\n";
    > echo "<input type=hidden name=\"returnmsg\"
    > value=\"acahomepage\">\n";
    >
    > } else {
    >
    > echo "action = /path to different cgi \n";
    > echo :different values for hidden fields".
    >
    > }
    I think you have pretty much figured it out. What I would do if I were
    dealing with this problem (just to make the code base more modular and
    easier to maintain) is this:

    form.html:

    <form method="post" action="login.php">
    <select name="loginform">
    <option value="1">Section 1</option>
    <option value="2">Section 2</option>
    </select>

    login.php:

    switch ($_POST['loginform']) {
    case 1:
    include ('form1.php');
    break;
    case 2:
    include ('form2.php');
    break;
    default:
    header ('Location: [url]http://'[/url] . $_SERVER['SERVER_NAME'] . '/form.html');
    die();
    }

    That is, if $_POST['loginform'] has a recognizable value, display
    the corresponding login form; if not, send the user back to the
    choice page. This allows you to have as many login forms as you
    want, totally independent of each other, using only one at a time.

    Cheers,
    NC
    Nikolai Chuvakhin Guest

  5. #4

    Default Re: Form processing: change the "action=" based on pull down menu

    [email]sylviestone@canada.com[/email] (Sylvie Stone) wrote in message news:<181a24a8.0309160650.45b744df@posting.google. com>...
    > Hi group -
    >
    > I have an html form for that uses username and password to login to a
    > specific area of the website. The "area" the user wants to go to is
    > based on a pull down menu. Becasue the user/password info is in
    > differnet databases, how can I call different validation scripts based
    > on this input ?
    > THANK YOU!

    THANKS A LOT to Erwin and NC for posting two excellent solutions.
    i have taken bits from each and implemented the code and it's working very well.

    Thanks again,

    Syl.
    Sylvie Stone Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139