One ...form... to rule them all?
I've been working on an experiment. Over time, I've noticed many of our landing page forms varied between 4 to 7 specific fields, each varying on whether it was a required field.
I decided to try making a landing page template where I could use just one form, and simply hide/unrequire fields if we didn't need them. I used several "mktoBoolean" metatags to toggle required status and field visibility. Then I applied Javascript for form verification, referencing a script I'd seen Sanford post in another thread. I tweaked here and there for my needs, and I'm almost there. But... still a few hurdles.
Rather than including a long code block, here's the experiment: go.idt911.com/validation-test.html ...I can follow up with any bits requested.
The challenges I've run into:
1. How to toggle the whole verification on/off? This is so, when I have to use a unique form, I can ignore that validation if it can't encompass whatever is in the unique form. This way, I could still use the landing page template for those situations. I made a boolean metatag (jsvalidate) to toggle. Then I tried wrapping the script in something like "if (jsvalidate != false) { //validation code }, but it didn't work.
2. Validating a Select field. Right now, I just have a regex to check if it's not empty, for proof-of-concept, but I believe there's a better way to validate select fields. The ways I tried, didn't work, though - they killed the script.
3. Simplifying things? As it's an experiment, and I'm no JS expert, there seem to be spots that could be streamlined. An example is a group of if statements, to add a " noRequire" class. They're each a little different, but I assume maybe there's a way to simplify. Maybe some array. But, I thought I'd get outside input before muddling through. Also, Maybe there's some way to have a 'multiple choice' toggle that covers all fields, instead of one for each?
4. Lastly... is this just a silly, insane idea? Are there reasons not to do it? I know it doesn't answer all scenarios - I'm just trying to prevent 100s of similar forms, if one will do.
included a screenshot of variables, for reference.
