mrbean Posted November 1, 2012 Share Posted November 1, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/ Share on other sites More sharing options...
thara Posted November 1, 2012 Share Posted November 1, 2012 do you need the same form twice in your page? Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/#findComment-1389245 Share on other sites More sharing options...
White_Lily Posted November 1, 2012 Share Posted November 1, 2012 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"); } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/#findComment-1389246 Share on other sites More sharing options...
brobert Posted November 1, 2012 Share Posted November 1, 2012 (edited) nvm... He got a better answer while I was typing Edited November 1, 2012 by brobert Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/#findComment-1389247 Share on other sites More sharing options...
kicken Posted November 1, 2012 Share Posted November 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/#findComment-1389248 Share on other sites More sharing options...
mrbean Posted November 1, 2012 Author Share Posted November 1, 2012 So the best way, is to give it an sort of prefix like: login_ signup_ contact_ reply_ Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/#findComment-1389250 Share on other sites More sharing options...
White_Lily Posted November 1, 2012 Share Posted November 1, 2012 try it and see, best way to learn what things do is to just play around with them. Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/#findComment-1389252 Share on other sites More sharing options...
Muddy_Funster Posted November 1, 2012 Share Posted November 1, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/#findComment-1389259 Share on other sites More sharing options...
White_Lily Posted November 1, 2012 Share Posted November 1, 2012 (edited) The link works fine for me. If you mean the edit-profile, then its because im still working on that file. Same with the view-profile as well. Thats true though some people learn by listening, some by reading, some by doing. Edited November 1, 2012 by White_Lily Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/#findComment-1389264 Share on other sites More sharing options...
Christian F. Posted November 1, 2012 Share Posted November 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270152-is-this-possible/#findComment-1389437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.