Jump to content

Is This Possible?


mrbean

Recommended Posts

for example I have 2 forms:

<form id="login_form" action="submit.php">
<input type="text" name="username">
<input type="password" name="password">
</form>

<form id="signup_form" action="submit.php">
<input type="text" name="username">
<input type="password" name="password">
</form>

With php I want to determinate if one of them is submitted.

If it is, do something with the password + username.

 

Both have the same input name, but is it possible to select only the inputs of a specific form even if they have the same name as other forms? If yes, how?

Link to comment
Share on other sites

if they have the same names then both forms would be submitted at the same time, like your suggesting i have developed a page with 2 forms.

 

http://janedealsart.co.uk/social/

 

to handle these to forms i had to give them seperate names.

 

<?php

$register = $_POST["register"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$uname = $_POST["uname"];
$pword = $_POST["pword"];
$rword = $_POST["pword_repeat"];
$gender = $_POST["gender"];
$login = $_POST["login"];
$username = $_POST["username"];
$password = $_POST["password"];

if(!empty($register)){
if(empty($fname) || empty($lname) || empty($lname) || empty($pword) || empty($rword)){
$regerr = "You must fill in the entire form.";
}else{
if($gender == ""){
$regerr .= "You need to also select a gender, if you don't want to share this simply select 'Not Telling'.";
}else{
if(strlen($uname) < 5 || strlen($uname) > 20){
$regerr .= "The username you entered is either to short or to long. They need to be between 6 and 20 characters long.";
}else{
if(strlen($pword) < 5){
$regerr .= "The password you entered is to short. They need to be at least 6 characters long.";
}else{
if($pword != $rword || $rword != $pword){
$regerr .= "The passwords do not match, re-enter them.";
}else{

$pattern = '#^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}$#';

if(preg_match($pattern, $pword)){

$usercheck = select("username", "users", "username = '$uname'");
$ucheck = mysql_fetch_assoc($usercheck);

if($ucheck == $uname){
$regerr .= "That username is already taken, try again.";
}else{

$folder = $uname;

$directory = $_SERVER["DOCUMENT_ROOT"]."/social/users/".$folder;
$dbdir = $GLOBALS["url"]."/social/users/".$folder;

if (!mkdir($directory, 0777, true)) {
$regerr .= "Failed to create user directory.";
}else{

$images = $_SERVER["DOCUMENT_ROOT"]."/social/users/".$folder."/images/";
if(!mkdir($images, 0777, true)){
$regerr .= "Failed to create user directory.";
}else{
$uploads = $_SERVER["DOCUMENT_ROOT"]."/social/users/".$folder."/uploads/";
if(!mkdir($uploads, 0777, true)){
$regerr .= "Failed to create user directory.";
}else{
$pword = sha1($pword);

$newUser = insert("users", "first_name, last_name, username, password, gender, directory", "'$fname', '$lname', '$uname', '$pword', '$gender', '$dbdir'");
if($newUser){
$regpas = "You have successfully registered. You may login now.";
}else{
$regerr .= "Could not register your details. Try again later.";
}
}
}
}
}
}else{
$regerr .= "Your password needs to have at least 1 capital letter and 1 digit in it.";
}
}
}
}
}
}
}

if(!empty($login)){
if(empty($username) || empty($password)){
$logerr = "You must enter the details you registered with before logging in.";
}else{

$compare = select("*", "users", "username = '$username'");
$get = mysql_fetch_assoc($compare);

if($username != $get["username"]){
$logerr .= "The username you entered is incorrect, try again.";
}else{

$password = sha1($password);

if($password != $get["password"]){
$logerr .= "The password you entered is incorrect, try again.";
}else{
session_start();
$_SESSION["user"] = $username;
$_SESSION["dir"] = $get["directory"];

header("Location: profile.php");

}
}
}
}

?>

Link to comment
Share on other sites

When you submit a form, the browser will only submit the elements that are contained within the <form> tag.  As for determining which form it was that was submitted on the PHP end of things, you need some element that you can check which differs between the forms.

Link to comment
Share on other sites

try it and see, best way to learn what things do is to just play around with them.

Not strictly true - different people respond better to different forms of learning stimulation. It may be that you learn better by playing about with things, but you can't rightly generalise that all learning by all people is better done the same way simply because it works for you.

 

Incidently - your view profile page on the forum in your sig is a 404 - not found

Link to comment
Share on other sites

mrbean: Not sure if you meant giving the fields a prefix, or the file processing the form. The latter option is the best one. Having two different scripts that does two different things is far preferable, than jumbling everything into one huge and messy soup.

Also, when you see files named register.php, login.php, and so forth, you'll instantly know what they do, as supposed to one submit.php. ;)

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.