Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <script src="https://rawgit.com/MisturDust319/formHelper/master/js/form.js"></script>
<div><label>Name: </label><span class="form_output"></span><input type="text" name="name" id="form_name" class="form-control"></div>
<div><label>Company: </label><span class="form_output"></span><input type="text" name="company" id="form_company" class="form-control"></div>
<div><label>Phone Number: </label><span class="form_output"></span><input type="text" name="phone_number" id="form_phone_number" class="form-control"></div>
<div><label>E-Mail: </label><span class="form_output"></span><input type="email" name="email" id="form_email" class="form-control"></div>
<div><label>Project Description & Comments: </label><span class="form_output"></span><textarea name="body" id="form_body" class="form-control"></textarea></div>
<br>
<button type="submit" class="btn btn-default btn-block" id="form_submit">Send</button>
            
          
!
            
              $(document).ready(function() {
  //a function to handle basic failure of field validation

  function fail(message) {
    $(this).parent().find(".form_output").html('<br><b class="text-danger text-right">' + message + '</b>');
  }

  function succeed(message) {
    $(this).parent().find(".form_output").html();
  }

  //a function to handle basic field data retrieval
  function fetchInfo() {
    return $(this).val();
  }

  function validateCompanion(data, companion) {
    //if data is filled out for this form, 
    //just return false to signify valid data
    if (data) {
      return false;
    }
    //return false if the companion's data is set
    else if ($(companion).val()) {
      return false;
    }
    //otherwise, return an error message
    else {
      return "You must include either an E-Mail Address or a Phone Number";
    }
  }

  //the phone number requires a custom validator list
  var phoneValidators = [{
      "validator": validateCompanion,
      "options": "companion"
    }, {
      "validator": validateNoHtml
    }, {
      "validator": validatePhoneNumber
    }]
    //custom validator list for the email field
  var emailValidators = [{
    "validator": validateCompanion,
    "options": "companion"
  }, {
    "validator": validateNoHtml
  }, {
    "validator": validateEmailAddress
  }]

  var formFields = [
    ["text", {
      name: "name",
      id: $("#form_name"),
      fetch: fetchInfo,
      success: succeed,
      failure: fail,
      required: true,
      min: 0,
      max: 100
    }],
    ["text", {
      name: "company",
      id: $("#form_company"),
      fetch: fetchInfo,
      success: succeed,
      failure: fail,
      required: true,
      min: 0,
      max: 100
    }],
    ["email", {
      name: "email",
      id: $("#form_email"),
      fetch: fetchInfo,
      success: succeed,
      failure: fail,
      required: true,
      validators: emailValidators,
      companion: "#form_phone_number"
    }],
    ["text", {
      name: "body",
      id: $("#form_body"),
      fetch: fetchInfo,
      success: succeed,
      failure: fail,
      required: true,
      min: 0,
      max: 4000
    }],
    ["text", {
      name: "phone_number",
      id: $("#form_phone_number"),
      fetch: fetchInfo,
      success: succeed,
      failure: fail,
      required: true,
      validators: phoneValidators,
      companion: "#form_email"
    }]
  ];

  contactDDi = new FieldHandler();
  contactDDi.makeFields(formFields);

  $(document).on("click", "#form_submit", function(event) {
    event.preventDefault();
    //reset the form's warnings
    $(this).parent().find(".form_output").html("");

    //get form data
    var data = contactDDi.getData();
    //if data is valid, continue to send form
    if (data) {
      alert("The data you input appears valid!");
    } else {
      alert("You appear to have made some mistakes on the form");
    }
  });
});
            
          
!
999px

Console