Next, to the task-specific input fields. Since most of your fields are hidden at any given time, it makes no sense to parse the entire form and save empty fields. It makes much more sense to see which service the user was interested in and then see if they filled in anything to the service-specific fields.
So, say someone was intersted in logo design. They would check the logo design checkbox on the HTML page and then complete the Company Name & Description fields. On the PHP form, we first use an
if statement to test to see if logo design is checked:
Code:
if (isset($_POST['services1'])) {
In English, again, this says that if there is a value from the services1 field (name= attribute), execute the following operations.
isset is testing for exactly what it seems like.
Is the value of services1
set (i.e. is it complete? Does it have a value? etc...)?
If it is, we parse the logo design specific fields:
Code:
if (isset($_POST['services1'])) {
$company_name = $_POST['comany_name'];
$company_description = $_POST['company_description'];
}
All of your checkboxes currently have a name= attribute of services. You'll want to make these unique and something different than the value= attribute. For my example, I use the logo_design fields with markup of:
Code:
<input type="checkbox" name="services1" value="logo_design" onClick="toggle_visibility(this.value)" /> Logo Design
Code:
Company Name: <br> <input type="text" name="company_name">
Business Description: <br><textarea name="company_description"></textarea>
Bookmarks