Form Configuration

" readonly="readonly" />

Form Fields

$field[1], 'fieldtype' => $field[2], 'fieldname' => $field[3], 'fieldoptions' => $field[4], 'fieldrequired' => $field[5], 'fieldvalidation' => $field[6] ); if ( key_exists( 7, $field ) ) $new_field_attrs = array_merge( $new_field_attrs, array( 'fieldlabel' => $field[7] ) ); // Echo the field editor html for the current field $form_fields_html .= get_new_contact_field( $count, $new_field_attrs ); $field_display_html .= get_new_contact_display( $count, $new_field_attrs ); $count++; } echo ''; echo $form_fields_html; } else { // No contact fields exist yet, just display an empty one echo ''; echo get_new_contact_field( '0', array( 'displayorder' => 1 ) ); } // Now we need to have a hidden blank field for jQuery to use // as a template to auto-magically add new fields to the page ?>

Enter the default value for this field or leave empty for no default value.

You may also use [[the_title]] or [[the_id]] to include the current post/page title or ID in the default field value.

Enter the options the user will be asked to select from, one option per line.

You may also use [[the_title]] or [[the_id]] to include the current post/page title or ID in an option.

$value ) { // Using a regex, check if it's one of our attribute fields (e.g. iwacf_fieldname_1) if ( preg_match( '/^iwacf\_[a-z]+\_[0-9]+$/', $key ) ) { // Split the array key on _ (e.g. ( [0] => iwacf, [1] => fieldname, [2] => 1) $attrs = preg_split( '/\_/', $key ); // Assign this attribute field's serial number to $field_no $field_no = $attrs[2]; // If this is a fieldname attribute, add the value of it to the $field_names array if ( $attrs[1] == 'fieldname' ) array_push( $field_names, $value ); // Create a new associative array containing the attribute name => value $array_item = array( $attrs[1] => $value ); // If the $form_fields associative array does not contain an array with this field number if ( !key_exists( $field_no, $form_fields ) || !is_array( $form_fields[$field_no] ) ) $form_fields[$field_no] = array(); // Add it to $form_fields as an empty array // Merge this attribute name=>value pair on to the $form_fields array $form_fields[$field_no] = array_merge( $form_fields[$field_no], $array_item ); } } // Now $form_fields is populated with all our attribute fields like; // array( [0] => array( 'fieldname' => 'My First Field', 'fieldtype' => 'input' ) , // [1] => array( 'fieldname' => 'My Second Field', 'fieldtype' => 'selectbox' ) ) $field_names_in_use = array( 'iwac_abval', 'iwac_abval_two', 'iwac_submitted', 'submit', 'iwac_form_id' ); $iwacontact_data = array(); $iwacontact_data_str = ''; $count = 0; // For each associative array in our $form_fields array foreach ( $form_fields as $field ) { // Increase the counter $count++; // Make the field name safe to be turned in to a html ID/name attribute $safe_field_name = mb_strtolower( trim( $field['fieldname'] ) ); // Clean leading/trailing white space and make the string lower case $safe_field_name = preg_replace( '/\ /', '_', $safe_field_name ); // Replace any spaces with underscores (_) $safe_field_name = preg_replace( "/[^a-zA-Z0-9-_]/", "", $safe_field_name ); // Remove any non alphanumeric characters $safe_field_name = ( strlen( $safe_field_name ) < 3 ) ? md5( microtime() ) : $safe_field_name; // If the established safe_field_name is already in use on this form, keep making up new ones until it becomes unique while ( in_array( $safe_field_name, $field_names_in_use ) ) $safe_field_name = md5( rand( 1,99 ) + time() + microtime() ); array_push( $field_names_in_use, $safe_field_name ); // Set some defaults in case anything is left empty $displayorder = ( key_exists( 'displayorder', $field ) ) ? $field['displayorder'] : $count; $fieldoptions = ( key_exists( 'fieldoptions', $field ) ) ? $field['fieldoptions'] : ''; $fieldrequired = ( key_exists( 'fieldrequired', $field ) ) ? $field['fieldrequired'] : ''; // Turn this field's attributes in to an array $field_data = array( $safe_field_name, $displayorder, $field['fieldtype'], $field['fieldname'], $fieldoptions, $fieldrequired, $field['fieldvalidation'], $field['fieldlabel'] ); // Turn the array in to a '::' separated string $field = join( '::', $field_data ); // Add the field on to the $iwacontact_data array array_push( $iwacontact_data, $field ); } // Turn the fields in $iwacontact_data in to a ';;' separated string $iwacontact_data_str = join( ';;', $iwacontact_data ); // Update all the post custom fields with our meta data update_post_meta( $post_id, 'iwacontact_data', $iwacontact_data_str ); update_post_meta( $post_id, 'iwacontact_sendto', trim( $_POST['iwacf_sendto'] ) ); update_post_meta( $post_id, 'iwacontact_subject', trim( $_POST['iwacf_subject'] ) ); update_post_meta( $post_id, 'iwacontact_from', trim( $_POST['iwacf_from'] ) ); update_post_meta( $post_id, 'iwacontact_submit_value', trim( $_POST['iwacf_submit_value'] ) ); } add_action( 'save_post', 'iwacontact_save_meta' ); /** * Return a new field in the admin edit contact form box * * @param integer $sequence The sequential number for this contact field * @param array $data The data to pre-populate this field with (if any) **/ function get_new_contact_display( $sequence, $data = array() ) { // If any necessary fields are empty, fill them with the default value $fieldname = ( key_exists( 'fieldname', $data ) ) ? $data['fieldname'] : 'New Field'; $fieldtype = ( key_exists( 'fieldtype', $data ) ) ? $data['fieldtype'] : 'input'; // Html for a new contact form field display return "
  • " . "$fieldname" . '
  • '; } /** * Return a new *hidden* field editor dialog in the admin edit contact form box * * @param integer $sequence The sequential number for this contact field * @param array $data The data to pre-populate this field with (if any) **/ function get_new_contact_field( $sequence, $data = array() ) { // If any necessary fields are empty, fill them with the default value $fieldname = ( key_exists( 'fieldname', $data ) ) ? $data['fieldname'] : 'New Field'; $fieldtype = ( key_exists( 'fieldtype', $data ) ) ? $data['fieldtype'] : 'input'; $fieldoptions = ( key_exists( 'fieldoptions', $data ) ) ? $data['fieldoptions'] : ''; $displayorder = ( key_exists( 'displayorder', $data ) ) ? $data['displayorder'] : ''; $fieldrequired = ( key_exists( 'fieldrequired', $data ) ) ? $data['fieldrequired'] : ''; $fieldvalidation = ( key_exists( 'fieldvalidation', $data ) ) ? $data['fieldvalidation'] : 'none'; $fieldlabel = ( key_exists( 'fieldlabel', $data ) ) ? $data['fieldlabel'] : '1'; $default_label_label = 'Default Value'; switch ( $field_type ) { case 'input': //break; case 'password': //break; case 'textarea': //break; case 'hidden': //break; case 'readonly': $default_label_label = 'Default Value '; break; case 'radio': //break; case 'selectbox': //break; case 'multiselect': $default_label_label = 'Options (1 per line) '; break; case 'checkbox': //break; case 'sendcopy': //break; case 'h1': //break; case 'h2': //break; case 'h3': //break; case 'h4': default: $default_label_label = 'Default Value '; break; } // Html for a new contact form field return "'; }