The extract() function is a quick and convenient way of grabbing form variables. Rather than going through the entire $_POST array assigning variables to each element, simply do the following:
extract( $_POST );
This creates a value pair corresponding to each key/value pair in the $_POST array (the elements in the contact form). So, the names in the posted form fields become the variable names, whose values are automatically assigned to their respective form values.
Take the following basic form:
<form action="emailSent.php" method="post">
<fieldset>
<legend>Personal information</legend>
<label>Name</label><input type="text" name="name" />
<label>Email address</label><input type="text" name="email" />
<label>Telephone</label><input type="text" name="phone" />
</fieldset>
<strong><label>Message</label>
<textarea name="message" ></textarea>
<input type="submit" name="SUBMIT" value="SUBMIT" />
</form>
Upon clicking ‘submit’, the form’s sent to the processing script, ‘emailSent.php’. There, the extract() function would appear:
extract( $_POST );
Which would immediately capture the $_POST array elements as:
$name=name;
$email=email;
$phone=phone;
Tags: contact form, php, php function, xhtml