';
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' ) )
$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
// 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 "
';
}
/**
* 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 "