Class : BCA/ BSC 2nd year
Subject: web development (data handling)
Subject type: vocational
Compiled by: Asst. Prof. Vibha barod
Form handling is the process of collecting and processing information that users submit through HTML forms.
In PHP, we use special tools called $_POST and $_GET to gather the data from the form. Which tool to use depends on how the form sends the data—either through the POST method (more secure, hidden in the background) or the GET method (data is visible in the URL).
1.Collecting Data: Retrieving form data using PHP.
2.Validating Data: Ensuring that the input meets expected formats.
3.Sanitizing Data: Cleaning up the data to prevent malicious content.
4.Processing Data: Using the data for its intended purpose (e.g., saving to a database, sending an email, etc.).
5.Returning a Response: Displaying feedback to the user or redirecting them to another page.
**Form Attributes**
1.action: The action attribute specifies the URL where the form data will be sent when the form is submitted.
<form method="post" action="process_form.php">
2.method: The method attribute specifies the HTTP method (GET or POST) to use when sending form data.
<form method="post" action="process_form.php">
3.name: The name attribute is crucial in PHP form handling, as it is used to refer to the data submitted by the form fields.
$username = $_POST['username']; // Accessing the form data
4.target: The target attribute specifies where to display the response after submitting the form. It determines where the resulting page (or response) will appear once the form is submitted.
<form method="post" action="process_form.php" target="_blank">
<input type="text" name="username" required>
<input type="submit" value="Submit">
</form>
5.enctype: The enctype (encoding type) attribute defines how the form data should be encoded when submitted to the server. This is particularly important when submitting forms that include file uploads.
Form Elements
Form processing contains a set of controls through which the client and server can communicate and share information. The controls used in forms are:
Input Field: Input field is the most common form element, allowing users to input a single line of text, such as their name, address, or any other simple text information.
<input type="text" name="fullname" required>
Password Input Field: The password input field hides the text entered, making it suitable for secure data entry like passwords.
<input type="password" name="password" required>
Checkboxes: Checkboxes allow users to select multiple options from a set of choices. They are often used for lists of features or permissions.
<input type="checkbox" name="subscribe" value="yes"> Subscribe to newsletter
Radio Buttons: Radio buttons allow the user to choose only one option from a set of predefined options. This is useful for binary choices, such as gender selection.
<input type="radio" name="gender" value="female"> Female
<input type="radio" name="gender" value="male"> Male
Textarea: The textarea element allows users to input multiple lines of text, making it useful for longer messages, feedback, or comments.
<textarea name="message" rows="5" cols="40" required></textarea>
0 comments:
Post a Comment