Today we will create a Registration form In PHP. It is like email address forms, registration forms, etc where the user can input the details. Before these, we also discussed PHP – Loops | for-loop, while-loop, do-while loop PHP Control Structures: If else, Switch Case, Data Type in PHP, Operators In PHP , Form In PHP if you don’t know then Hurry up Now!
Definition and Usage
In HTML, the <form> tag is used to create an HTML form for user input.
It contains many elements some are given below:
- <input>
- <textarea>
- <button>
- <select>
- <option>
- <outgroup>
- <fieldset>
- <label>
- <output>
What do you mean by the Registration form?
In PHP, the registration form is a list of areas in which a user will input data and submit it. It is useful in every case where registration is necessary.
For Example, Various companies and institutions use registration forms to sign up customers for services, or other programs.
In Schools and colleges, a registration form is used to register students in which students can fill their contact information, etc.
Let’s take some examples of registration forms in PHP.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Admission form</title> </head> <body> <div class="box"> <form action="" id="register" method="post"> <p>Admission form</p> <div class="inner-box"> <label for="stream1">Stream type</label><br> <select name="stream1" id="stream1"> <option value="Not selected">Select your Stream type</option> <option value="Plus two">+2</option> <option value="Plus three">+3</option> </select><br><br> <label for="stream2">Stream </label><br> <select name="stream2" id="stream2"> <option value="Not selected">Select your Stream</option> <option value="Arts">Arts</option> <option value="Commerce">Commerce</option> <option value="Science">Science</option> </select><br><br> <label for="adate">Admission Date</label><br> <input type="date" class="adate" id="adate" name="adate" placeholder="Enter your admission date"><br><br> <label for="name">Name</label><br> <input type="text" class="name" id="name" name="name" placeholder="Enter your name"><br><br> <label for="roll">Roll no</label><br> <input type="text" class="roll" id="roll" name="roll" placeholder="Enter your roll no"><br><br> <label for="gender" class="gender">Gender<br> <input type="radio" name="gender" id="gender" value="Male">Male <input type="radio" name="gender" id="gender" value="Female">Female <input type="radio" name="gender" id="gender" value="Other">Other </label><br><br> <label for="caste">Caste<br> <input type="radio" name="caste" id="caste" value="obc">obc <input type="radio" name="caste" id="caste" value="st">st <input type="radio" name="caste" id="caste" value="sc">sc <input type="radio" name="caste" id="caste" value="general" >general </label><br><br> <label for="address">Address</label><br> <textarea name="address" id="address" cols="133" rows="5" placeholder="Enter your address"></textarea><br><br> <label for="Email">Email:</label><br> <input type="email" name="email" id="email" placeholder="Enter your Email"><br><br> <label for="contactno">Contact No</label><br> <input type="tel" class="contactno" id="contactno" name="contactno" placeholder="Enter your contact no"><br><br> <label for="adharno">Adhar No</label><br> <input type="text" class="adharno" id="adharno" name="adharno" placeholder="Enter your adharno"><br><br> <button id="submit" name="submit" value="submit" >Submit</button> </div> </form> </div> </body> </html>
OUTPUT
Example, Form Using HTML, CSS, PHP
<! Doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title> PHP Registration Form </title> <style> input[type=radio] { width:20px; } input[type=checkbox]{ width:20px; } * { padding: 0; margin: 0; box-sizing: border-box; } body { margin: 50px auto; text-align: center; width: 800px; } input[type=reset] { border: 3px solid; border-radius: 2px; color: ; display: block; font-size: 1em; font-weight: bold; margin: 1em auto; padding: 1em 4em; position: relative; text-transform: uppercase; } input[type=reset]::before { background: #fff; content: ''; position: absolute; z-index: -1; } input[type=reset]]:hover { color: #1A33FF; } input { border: 2px solid #ccc; font-size: 1rem; font-weight: 100; font-family: 'Lato'; padding: 10px; } form { margin: 20px auto; padding: 20px; border: 5px solid #ccc; background: #8bb2eafa; } h1 { font-family: sans-serif; display: block; font-size: 2rem; font-weight: bold; text-align: center; letter-spacing: 3px; color: hotpink; text-transform: uppercase; } input[type=submit] { border: 3px solid; border-radius: 2px; color: ; display: block; font-size: 1em; font-weight: bold; margin: 1em auto; padding: 1em 4em; position: relative; text-transform: uppercase; } input[type=submit]::before { background: #fff; content: ''; position: absolute; z-index: -1; } input[type=submit]:hover { color: #bdc5ff; } </style> </head> <body> <h1> Registration Form </h1> <form method="post" enctype="multipart/form-data" action =?#?> <table> <tr> <td colspan="2"> <?php echo @$msg; ?> </td> </tr> <tr> <td width="159"> <b> Enter your Name </b> </td> <td width="218"> <input type="text" placeholder="Enter name" name = "n" pattern="[a-z A-Z]*" required /> </td> </tr> <tr> <td> <b> Enter your Email </b> </td> <td> <input type="email" name="e"/ placeholder= "Enter Email" > </td> </tr> <tr> <td> <b> Enter your Password </b> </td> <td> <input type="password" name="p"/ placeholder=" Enter Password" > </td> </tr> <tr> <td> <b> Enter your Address </b> </td> <td> <textarea name="add"> Enter Address </textarea> </td> </tr> <tr> <td> <b> Enter your Mobile Number </b> </td> <td> <input type="text" pattern="[0-9]*" name="m" / placeholder=" Enter number" > </td> </tr> <tr> <td height="23"> <b> Select your Gender </b> </td> <td> Male <input type="radio" name="g" value="m"/> Female <input type="radio" name="g" value="f"/> </td> </tr> <tr> <td> <b> Choose your Hobbies </b> </td> <td> Cricket <input type="checkbox" value="cricket" name="hobb[]"/> Singing <input type="checkbox" value="singing" name="hobb[]"/> Dancing <input type="checkbox" value="dancing" name="hobb[]"/> </td> </tr> <tr> <td> <b> Select your Profile Pic </b> </td> <td> <input type="file" name="pic"/> </td> </tr> <tr> <td> <b> Select your Date of Birth </b> </td> <td> <select name="mm"> <option value=""> Month </option> <?php for($i=1;$i<=12;$i++) { echo "<option value ='$i'>".$i."</option>"; } ?> </select> <select name="dd"> <option value=""> Date </option> <?php for($i=1;$i<=31;$i++) { echo "<option value ='$i'>".$i."</option>"; } ?> </select> <select name="yy"> <option value=""> Year </option> <?php for($i=1900;$i<=2015;$i++) { echo "<option value ='$i'>".$i."</option>"; } ?> </select> </td> </tr> <tr> <td colspan="2" align="center"> <input type ="submit" name="save" value="Register"/> <input type="reset" value="Reset"/> </td> </tr> </table> </form> </body> </html> <?php extract($_POST); if(isset($save)) { $dob=$yy."-".$mm."--".$dd; $h=implode(",",$hobb); $img=$_FILES['pic']['name']; if($return) { } else { } } ?>
OUTPUT: