Submit API All Fields Example

Introduction

As you can see in the section dedicated to [form fields], it’s important that the data submitted to Wufoo’s servers is properly formatted. An American phone number, for example is submitted as 1234567890 and not 123-456-897. This example will not go into nearly as much detail as the Basic Example, but rather take a brief look at how some of the different fields are submitted to Wufoo, and how the error messages are returned.

The Files

Download The Files

The Easy Fields

The easy fields are very straight forward. They’re fields like a text field or number field that require no formatting and consist of only one value. In the example, these are our easy fields:

    '0' => $_POST['Field0'],//text
    '8' => $_POST['Field8'], //paragraph
    '115' => $_POST['Field115'], //email
    '114' => $_POST['Field114'], //website
    '9' => $_POST['Field9'], //number
    '112' => $_POST['Field112'], //radio
    '111' => $_POST['Field111'], //dropdown

The Multi-Fields

Some fields actually consist of more than one field. Address, for example, consists of street, street1, city, state, zip, and country. Each field is submitted separately, and each field will be validated separately. In our example, the address is submitted like this:

    '2' => $_POST['Field2'], //address
    '3' => $_POST['Field3'],
    '4' => $_POST['Field4'],
    '5' => $_POST['Field5'],
    '6' => $_POST['Field6'],
    '7' => $_POST['Field7'], 

Wufoo will validate each field, and if you remember in the section on Form Fields,

If the address field is a required field, all fields besides the second street field are required.

The Tricky Fields

Where the last two field types are pretty straight forward, there are some fields that need formatting before Wufoo will accept them as valid. In our example, these fields are the ones that require a little bit of formatting before being sent over to Wufoo:

    '1' =>  $_POST['Field1'].$_POST['Field1-1']. $_POST['Field1-2'], //date
    '113' =>  $_POST['Field113'].$_POST['Field113-1']. $_POST['Field113-2'], //phone
    '116' =>  $_POST['Field116']. addCharacter($_POST['Field116-1'], '.') .$_POST['Field116-1'], //money 
    '117' =>  $_POST['Field117']. addCharacter($_POST['Field117-1'], ':') . $_POST['Field117-1']. addCharacter($_POST['Field117-2'], ':') .  $_POST['Field117-2'], //time 

Fields like date and phone are numeric only and although we had three fields for the user to enter data into, we only send over one variable containing all of the date and phone information to Wufoo.

If you take a look at money and time, you’ll see a function calling addCharacter.

function addCharacter($field, $character){
    if ($field != '') return $character;
}

Time, for example, requires a “:” between the hours and minutes, and the minutes and seconds. Without the proper formatting, there is a good chance that the data won’t validate, and if it does validate, the correct information may not be submitted and stored.

Updated : February 15th, 2007