ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Contact Form with Required Fields

August 29, 2007 5:37pm

Subscribe [2]
  • #1 / Aug 29, 2007 5:37pm

    mpace

    20 posts

    I have a simple contact form with name, email, phone number, drop down.

    In order for me to receive the email with all the filled out values, I have to use name=“message[]” for all these fields.

    What if I want them to be required as well? It says I have to use name=“required[]”

    This is sort of a rush job so I don’t want to set up free form or learn how to use it right at the moment, so just wondering if I’m missing something with the built in contact form.

    THanks

    <label for="name">Name:</label>
    
    <input type="text" id="name" name="message[]" size="40" />
    <label for="Age">Age:</label>
    
    <input type="text" id="age" name="message[]" size="40" />
    
    <label for="phone">Phone Number:</label>
    
    <input type="text" id="phone" name="message[]" size="40" />
    
    <label for="pc">Postal Code:</label>
    
    <input type="text" id="pc" name="message[]" size="40" />
  • #2 / Aug 29, 2007 7:04pm

    grantmx

    1439 posts

    Other than using Javascript to validate, from what I seen freeform is the best option.  And its quite easy and quick.  But here is the java if you want it.

    The java code:

    <!--
    function MM_validateForm() { //v4.0
      if (document.getElementById){
        var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
        for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
          if (val) { nm=val.name; if ((val=val.value)!="") {
            if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
              if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
            } else if (test!='R') { num = parseFloat(val);
              if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
              if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
                min=test.substring(8,p); max=test.substring(p+1);
                if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
          } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
        } if (errors) alert〈'The following error(s〉 occurred:\n'+errors);
        document.MM_returnValue = (errors == '');
    } }
    //-->

    Within the form:

    <code><form action="" method="post" name="form1" id="form1"  document.MM_returnValue"></code>
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases