Blog Remove Unwanted Items from $_POST Array
If the contact form had 10 fields, 20 fields or more, the loop would process each one and create an email message. This script was being used on multiple websites and I didn’t want to custom tailor each one to match the form fields.
However, the $_POST[‘submit’] variable was coming through as well along with its value of Send. This was quite easy to remove with the unset PHP function.
Before the loop started, I executed the unset function on the fields I didn’t want to include. The loop then ran and my email message included only the necessary fields.
This would also be useful to run on $_POST[‘recaptcha_challenge_field’] and $_POST[‘recaptcha_response_field’] after they have been utilized to remove those fields as well.