Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Self-Processing PHP Form Re: Self-Processing PHP Form

#112907

Okay, so I’ve created a self-processing PHP form that builds itself dynamically based on a configuration array.

$inputFields = array(
// Which fields do you want the contact form to include?
// FORMAT: array(referenceKey (no spaces), Display Name, fieldType, isRequired?),
array(‘name’, ‘Name’, ‘text’, true),
array(‘phone’, ‘Phone Number’, ‘text’, true),
array(’email’, ‘Email Address’, ‘text’, false),
array(‘source’, ‘Source’, ‘text’, false),
array(‘message’, ‘How can we help you?’, ‘textarea’, true),
);

I’ve hit a slight road block, as I’m not sure how I should approach dynamic validation of the data passed into the forms. Each field has different validation that goes further than just determining if a required field is blank (email address will be validated via REGEX differently than a phone number). I need a way to be able to validate many different types of input, without knowing explicitly what they are.

I can obviously use pre-fit reference keys (email for email address, name for name, phone for phone number, etc.), but that isn’t something that’s very user friendly, as that all has to be documented and places limitations on the code. For the complete code, you can visit [GitHub](https://github.com/NicholasRBowers/Self-Processing-PHP-Form). Ideas?