$data['callback_args'] = '';
$data['visibility_control'] = '';
$data['style'] = file_get_contents(CCTM_PATH . '/css/validation.css');
// Save if submitted...
if (!empty($_POST) && check_admin_referer($data['action_name'], $data['nonce_name'])) {
    $def = CCTM_Metabox::sanitize($_POST);
    unset($def['old_id']);
    if (CCTM_Metabox::is_valid_def($_POST)) {
        CCTM::$data['metabox_defs'][$def['id']] = $def;
        CCTM::set_flash(CCTM::format_msg(__('Metabox created.', CCTM_TXTDOMAIN)));
        $continue_editing = CCTM::get_value($_POST, 'continue_editing');
        unset($_POST);
        if ($continue_editing) {
            CCTM::redirect('?page=cctm&a=edit_metabox&id=' . $def['id']);
        } else {
            CCTM::redirect('?page=cctm');
        }
        return;
    } else {
        $data['msg'] = CCTM::format_error_msg(CCTM_Metabox::$errors, __('Please correct the following problems.', CCTM_TXTDOMAIN));
        foreach (CCTM_Metabox::$errors as $field => $error) {
            $data[$field . '.error'] = sprintf('<span class="cctm_validation_error">%s</span>', $error);
            $data[$field . '.error_class'] = 'cctm_validation_error';
        }
    }
    // Repopulate
    foreach ($def as $k => $v) {
        $data[$k] = $v;
    }
}
$data['rows'] = '';
Example #2
0
 /**
  * Callback function used by the cctm_post_form() function.  This is what gets 
  * called 
  *
  * @param	array $args: parameters from the shortcode and posted data
  * @return string (printed)	 
  */
 public static function post_form_handler($args)
 {
     //return print_r($args,true);
     // Strip out the control stuff (keys begin with underscore)
     $vals = array();
     foreach ($args as $k => $v) {
         if ($k[0] == '_') {
             continue;
         }
         $vals[$k] = $v;
     }
     // Insert into Database
     $email_only = CCTM::get_value($args, '_email_only');
     if (!$email_only) {
         require_once CCTM_PATH . '/includes/SP_Post.php';
         $P = new SP_Post();
         CCTM::$post_id = $P->insert($vals);
     }
     // Email stuff
     if (isset($args['_email_to']) && !empty($args['_email_to']) && isset($args['_email_tpl']) && !empty($args['_email_tpl'])) {
         $Q = new GetPostsQuery();
         $P = $Q->get_post($args['_email_tpl']);
         //return print_r($P, true);
         $subject = $P['post_title'];
         $message_tpl = wpautop($P['post_content']);
         // If the 'My User' <*****@*****.**> format is used, we have to manipulate the string
         // to keep WP from tripping over itself
         $from = CCTM::get_value($args, '_email_from', get_bloginfo('admin_email'));
         $from = str_replace(array('&#039', '&#034;', '&quot;', '&lt;', '&gt;'), array("'", '"', '"', '<', '>'), $from);
         // die(print_r($args,true));
         $subject = CCTM::get_value($args, '_email_subject', $subject);
         $headers = 'From: ' . $from . "\r\n";
         $headers .= 'content-type: text/html' . "\r\n";
         $message = CCTM::parse($message_tpl, $vals);
         if (!wp_mail($args['_email_to'], $subject, $message, $headers)) {
             return "There was a problem sending the email.";
         }
     }
     // Redirect or show a simple message.
     $redirect = CCTM::get_value($args, '_redirect');
     if ($redirect) {
         $url = get_permalink($redirect);
         CCTM::redirect($url, true);
     }
     // Else, return message:
     return CCTM::get_value($args, '_msg', "Thanks for submitting the form!");
 }