Jump to content

Multiple option button


phpnewbie112

Recommended Posts

Hello,

 

I have 2 fields username and password inside a form + 3 options (member, affiliate and admin) each one has different file (member.php, affiliate.php and admin.php) thus each option have a different post file. how can you do it in php to have 1 form with the mentioned but forwarding to the selected option file. thank you

Link to comment
Share on other sites

You can try like this, after your username and password field suppose you have list box from where user will select his type

<form id="form1" name="form1" method="post" action="<?=$curPage?>">

<select name="user_type" id="user_type">
<option>----------------------</option>
<option value="Affilate">Affilate</option>
<option value="Member">Member</option>
<option value="Admin">Admin</option>
</select>
<input type="submit" name="Submit" value="Submit" />
</form>

 

and in the same page you keep this

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$user_type = $_POST['user_type']; 

switch ($user_type)
{
case "Affilate":
$curPage = "affilate.php";
break;
case "Member":
$curPage = "member.php";
break;
case "Admin":
$curPage = "admin.php";
break;
}
}

?>

 

Hope, you get the idea.

Link to comment
Share on other sites

thanks for the help, I would really appreciate if you can advice what to do in my situation:

 

each file let's take for example: admin.php include variables and all sql procedures to check whether the user/pass are correct. moving these codes into the single file (the one with the form and 3 options) is complicated for me. is there any way I can include them so that when I do a submit it goes to the given file and do the necessary checkups? thanks a million

Link to comment
Share on other sites

I think including the file will work...

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$user_type = $_POST['user_type']; 

switch ($user_type)
{
case "Affilate":
        require_once("affilate.php"); //added here 
$curPage = "affilate.php";
break;
case "Member":
        require_once("member.php");// here 
$curPage = "member.php";
break;
case "Admin":
        require_once("admin.php");// and here
$curPage = "admin.php";
break;
}
}

?>

 

 

Link to comment
Share on other sites

This should work now , I tried this  ;D

index.php

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$user_type = $_POST['user_type']; 

switch ($user_type)
{
case "Affilate":
    require_once("affilate.php"); 
echo $var;
break;
case "Member":
    require_once("member.php"); 
echo $var;
break;
case "Admin":
    require_once("admin.php");
echo $var;
break;
}
}

?>
<table width="474" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="474" height="228" valign="top"><form id="form1" name="form1" method="post">

<select name="user_type" id="user_type">
<option>----------------------</option>
<option value="Affilate">Affilate</option>
<option value="Member">Member</option>
<option value="Admin">Admin</option>
</select>
<input type="submit" name="Submit" value="Submit" />
</form><!--DWLayoutEmptyCell--> </td>
</tr>
</table>

 

And in affilate.php, member.php and admin.php keep this code

<?php
// just change the string in all 3 pages ADMIN, MEMBER and AFFILATE
$var = "You are in ADMIN page"; 
?>

Link to comment
Share on other sites

I mean if I choose affilate.php it open the affilate pages but what I want is to be opened and perform the validation of the username and password thus if the user/pass are correct it moves to the management page.

 

the page affilate.php already have a part for login as well as the other pages. My question is to merge all these logins in one page with select option...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.