(object)array( 'label' => 'Textinput', 'render' => 'scf_render_input_text' ), 'textarea' => (object)array( 'label' => 'Textarea', 'render' => 'scf_render_textarea' ), 'select' => (object)array( 'label' => 'Select', 'render' => 'scf_render_select' ), 'radio' => (object)array( 'label' => 'Radios', 'render' => 'scf_render_checkbox_radio', 'element_container_class' => 'scf-radios' ), 'checkbox' => (object)array( 'label' => 'Checkboxes', 'render' => 'scf_render_checkbox_radio', 'element_container_class' => 'scf-checkboxes' ) ); $scf_mandatory_fields = array( 'name' => 'input-text:Name', 'email' => 'input-text:E-Mail', 'message' => 'textarea:Message' ); $scf_default_options = array( 'scf_fields' => join( '~', array( join( ':', array( 'name', 0, true, 'input-text', '', 'Name' ) ), join( ':', array( 'email', 1, true, 'input-text', '', 'E-Mail' ) ), join( ':', array( 'subject', 2, false, 'input-text', '', 'Subject' ) ), join( ':', array( 'message', 3, true, 'textarea', '', 'Message' ) ) ) ), 'scf_use_captcha' => true, 'scf_recipient_email' => 'you@example.com', 'scf_recipient_subject' => 'Contact Request from your Website!', 'scf_success_message' => 'Thanks for your comments!', 'scf_error_message' => 'Please fill in the required fields marked with *', 'scf_captcha_error' => 'Sorry, the Captcha didnt fit', 'scf_captcha_label' => 'Please type in the captcha', 'scf_submit_value' => 'Submit Request' ); /* OPTIONS */ function scf_init_options( $resettable = false ) { global $scf_mandatory_fields, $scf_default_options; $mandatory_fields = array_merge( array(), $scf_mandatory_fields ); $options = array(); foreach ( $scf_default_options as $n => $v ) { // init default value for option if ( $resettable && isset( $_GET[ 'reset' ] ) && $_GET[ 'reset' ] == '1' ) delete_option( $n ); add_option( $n, $v ); // read current ootion $options[ $n ] = stripslashes( get_option( $n ) ); } $fields_pre = split( '~', $options[ 'scf_fields' ] ); $fields = array(); $max_num = 0; foreach ( $fields_pre as $pre ) { $f = split( ':', $pre, 6 ); $values = split( ';', $f[4] ); // remove mandatory field from list .. $mandatory = false; if ( isset( $mandatory_fields[ $f[0] ] ) ) { $mandatory = true; $f[2] = true; unset( $mandatory_fields[ $f[0] ] ); } // determine max num for saving next .. elseif ( preg_match( '/^custom_(\d+)$/', $f[0], $m ) ) { if ( $m[1] > $max_num ) $max_num = $m[1]; } // this is easier to use .. $fields []= (object)array( 'name' => $f[0], 'position' => $f[1], 'required' => $f[2], 'mandatory' => $mandatory, 'type' => $f[3], 'values' => $values, 'label' => $f[5], ); } // store maximum custom num .. $options[ 'scf_max_custom' ] = $max_num; // append all mandatory fields! foreach ( $mandatory_fields as $name => $v ) { $f = split( ':', $v, 2 ); $fields []= (object)array( 'name' => $name, 'position' => 0, 'required' => true, 'mandatory' => true, 'type' => $f[0], 'values' => array(), 'label' => $f[1], ); } usort( $fields, 'scf_sort_fields' ); $options[ 'scf_count_fields' ] = count( $fields ); $options[ 'scf_fields' ] = $fields; return $options; } /* FORMULAR */ function scf_init_form( $options ) { $newCaptcha = scf_get_captcha_instance(); // decide wheter use captcha $print_captcha = $options[ 'scf_use_captcha' ] == 1 ? 1 : 0; $result = array( 'use_captcha' => $print_captcha, 'try_save' => false ); // check / send contact fomular if ( !empty( $_POST ) ) { $result[ 'try_save' ] = true; $captcha_ok = true; // check the captcha if ( $print_captcha ) { $captcha_ok = false; @session_start(); $publicKey = $_POST['scf_captcha']; $secretKey = $_SESSION['secret']; $captcha_ok = $newCaptcha->validateKey($publicKey, $secretKey); } // captcha doesnt fit .. if ( ! $captcha_ok ) { $result[ 'form_error' ] = true; $result[ 'result_class' ] = 'scf-captcha-error'; $result[ 'result_message' ] = $options[ 'scf_captcha_error' ]; } // captcha OK else { // try now sending .. if succeeded -> print success and return if ( scf_check_and_send_form( $options, $_POST ) ) { $result[ 'form_error' ] = false; $result[ 'result_class' ] = 'scf-form-success'; $result[ 'result_message' ] = $options[ 'scf_success_message' ]; } // or print error and print form else { $result[ 'form_error' ] = true; $result[ 'result_class' ] = 'scf-form-error'; $result[ 'result_message' ] = $options[ 'scf_error_message' ]; } } } return (object)$result; } function scf_print_contact_form( $content = "" ) { global $scf_field_types; $newCaptcha = scf_get_captcha_instance(); $options = scf_init_options(); $form = scf_init_form( $options ); $permalink = get_permalink(); $captcha_url = scf_check_simple_captcha(); $print_captcha = $captcha_url !== null && $options[ 'scf_use_captcha' ] == 1; $str = << HTML; if ( $form->try_save && ! $form->form_error ) $str .= << $form->result_message HTML; else { $str .= << HTML; if ( $form->try_save && $form->form_error ) $str .= << $form->result_message HTML; foreach ( $options[ 'scf_fields' ] as $field ) { $str .= << HTML; $str .= call_user_func( $scf_field_types[ $field->type ]->render, $field ); $str .= << HTML; } if ( $print_captcha ) { $bloginfo_url = get_bloginfo('url'); $str .= <<
HTML; } $str .= << HTML; } $str .= << HTML; return $str; } function scf_print_contact_form_ajax( $content = "" ) { $str = << HTML; $str .= scf_print_contact_form( $content ); $str .= << HTML; return $str; } function scf_render_label_simple( $field ) { $str = <<