Totally custom html form inside account tab
-
Hello, Is it possible to allow custom html form submission inside ultimate member account nav?
We want to avoid custom form builder, too much time with clicks and settings and we are coders.
Some screenshots of what I mean.
Viewing 2 replies - 1 through 2 (of 2 total)
-
Hi @amast7
You can try creating a form for an account tab with this tutorial. In the tutorial, you will be able to use the Profile form as an Account form in a custom tab.
Regards,
remove_action('um_before_form', 'um_add_update_notice', 500); add_action('um_before_form', 'um_add_addrecipe_notice', 10); function um_add_addrecipe_notice($args) { extract($args); $output = ''; $err = ''; $success = ''; if (!empty($_REQUEST['updated']) && !UM()->form()->errors) { if (UM()->account()->current_tab == 'addrecipe') { $success = __('Η συνταγ? προστ?θηκε.', 'exis'); } else { switch ($_REQUEST['updated']) { default: /** * UM hook * * @type filter * @title um_custom_success_message_handler * @description Add custom success message * @input_vars * [{"var":"$success","type":"string","desc":"Message"}, * {"var":"$updated","type":"array","desc":"Updated data"}] * @change_log * ["Since: 2.0"] * @usage * <?php add_filter( 'um_custom_success_message_handler', 'function_name', 10, 2 ); ?> * @example * <?php * add_filter( 'um_custom_success_message_handler', 'my_custom_success_message', 10, 2 ); * function my_custom_success_message( $success, $updated ) { * // your code here * return $success; * } * ?> */ $success = apply_filters('um_custom_success_message_handler', $success, $_REQUEST['updated']); break; case 'account': $success = __('Your account was updated successfully.', 'ultimate-member'); break; case 'password_changed': $success = __('You have successfully changed your password.', 'ultimate-member'); break; case 'account_active': $success = __('Your account is now active! You can login.', 'ultimate-member'); break; } } } if (!empty($_REQUEST['err']) && !UM()->form()->errors) { switch ($_REQUEST['err']) { default: /** * UM hook * * @type filter * @title um_custom_error_message_handler * @description Add custom error message * @input_vars * [{"var":"$error","type":"string","desc":"Error message"}, * {"var":"$request_error","type":"array","desc":"Error data"}] * @change_log * ["Since: 2.0"] * @usage * <?php add_filter( 'um_custom_error_message_handler', 'function_name', 10, 2 ); ?> * @example * <?php * add_filter( 'um_custom_error_message_handler', 'my_custom_error_message', 10, 2 ); * function my_custom_error_message( $error, $request_error ) { * // your code here * return $error; * } * ?> */ $err = apply_filters('um_custom_error_message_handler', $err, $_REQUEST['err']); if (!$err) { $err = __('An error has been encountered', 'ultimate-member'); } break; case 'registration_disabled': $err = __('Registration is currently disabled', 'ultimate-member'); break; case 'blocked_email': $err = __('This email address has been blocked.', 'ultimate-member'); break; case 'blocked_domain': $err = __('We do not accept registrations from that domain.', 'ultimate-member'); break; case 'blocked_ip': $err = __('Your IP address has been blocked.', 'ultimate-member'); break; case 'inactive': $err = __('Your account has been disabled.', 'ultimate-member'); break; case 'awaiting_admin_review': $err = __('Your account has not been approved yet.', 'ultimate-member'); break; case 'awaiting_email_confirmation': $err = __('Your account is awaiting e-mail verification.', 'ultimate-member'); break; case 'rejected': $err = __('Your membership request has been rejected.', 'ultimate-member'); break; case 'invalid_nonce': $err = __('An error has been encountered. Probably page was cached. Please try again.', 'ultimate-member'); break; } } if (!empty($err)) { $output .= '<p class="um-notice err"><i class="um-icon-ios-close-empty" onclick="jQuery(this).parent().fadeOut();"></i>' . $err . '</p>'; } if (!empty($success)) { $output .= '<p class="um-notice success"><i class="um-icon-ios-close-empty" onclick="jQuery(this).parent().fadeOut();"></i>' . $success . '</p>'; } echo $output; } add_action('um_submit_account_addrecipe_tab_errors_hook', 'my_submit_account_tab_errors', 10); function my_submit_account_tab_errors() { $_REQUEST['updated'] = 'addrecipe'; if ($_POST['_um_account_tab'] == 'addrecipe') { if (!$_POST['post_title']) UM()->form()->add_error('post_title', __('Ο τ?τλο? ε?ναι υποχρεωτικ?? *', 'exis_recipe')); if (!$_POST['page_content']) UM()->form()->add_error('page_content', __('Η μ?θοδο? εκτ?λεση? ε?ναι υποχρεωτικ? *', 'exis_recipe')); if (!$_POST['ingredients']) UM()->form()->add_error('ingredients', __('Τα υλικ? ε?ναι υποχρεωτικ? *', 'exis_recipe')); if (!$_FILES['image']) UM()->form()->add_error('image', __('Η φωτογραφ?α ε?ναι υποχρεωτικ? *', 'exis_recipe')); if ($_FILES['image']) { $mime_type = $_FILES['image']['tmp_name'] ? mime_content_type($_FILES['image']['tmp_name']) : []; //check for file type $allowed_file_types = ['image/png', 'image/jpeg', 'application/bmp', 'image/jpg']; if (!in_array($mime_type, $allowed_file_types)) { UM()->form()->add_error('image', __('Η φωτογραφ?α δεν ε?ναι ?γκυρη.', 'exis')); } //check for file size $max_size = 524288; //512KB if ($_FILES['size'] > $max_size) { UM()->form()->add_error('image', __('Υπ?ρχε σφ?λμα κατ? την καταχ?ρηση τη? εικ?να?, παρακαλ? προσπαθε?στε π?λι.', 'exis')); } $_POST['_um_account_tab'] = 'addrecipe'; } } } add_action('um_account_tab__addrecipe', 'um_account_tab__addrecipe'); function um_account_tab__addrecipe($info) { global $ultimatemember; extract($info); $output = $ultimatemember->account->get_tab_output('addrecipe'); if ($output) { echo $output; } } add_filter('um_account_content_hook_addrecipe', 'um_account_content_hook_addrecipe'); function um_account_content_hook_addrecipe($output) { ob_start(); get_template_part('inc/my-recipes/add-recipe-form'); $output .= ob_get_contents(); ob_end_clean(); return $output; } add_action('um_account_pre_update_profile', 'getUMFormData', 100); function getUMFormData() { if (isset($_POST['action']) && $_POST['action'] == 'my_acc_add_recipe') { if (wp_verify_nonce($_POST['_wpnonce'], 'my_acc_add_recipe') != false) { $image = $_FILES['image']; if (UM()->form()->count_errors() == 0) { $post_args = [ 'post_author' => get_current_user_id(), 'post_content' => sanitize_text_field($_POST['page_content']), 'post_title' => sanitize_text_field($_POST['post_title']), 'post_status' => 'draft', 'post_type' => 'recipe', ]; $post_id = wp_insert_post($post_args); if ($post_id) { require_once(ABSPATH . 'wp-admin/includes/admin.php'); $category_term = get_term_by('slug', $_POST['category'], 'recipe-category'); wp_set_object_terms($post_id, $category_term->term_id, 'recipe-category'); //update acf fields update_field('recipe-parts', sanitize_text_field($_POST['portions']), $post_id); update_field('recipe-preparation-time', sanitize_text_field($_POST['time']), $post_id); update_field('acf_recipe_ingredients_repeater', $_POST['ingredients'], $post_id); $file_return = wp_handle_upload($image, ['test_form' => false]); //if not uploaded and returned error, delete the post if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) { wp_delete_post($post_id); } else { $filename = $file_return['file']; $attachment = [ 'post_mime_type' => $file_return['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit', 'guid' => $file_return['url'] ]; $attachment_id = wp_insert_attachment($attachment, $file_return['url']); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); wp_update_attachment_metadata($attachment_id, $attachment_data); update_post_meta($post_id, '_thumbnail_id', $attachment_id); } } }//if empty errors }//if verify nonce }//if action and post action }
I used the code above and worked, thanks!
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Totally custom html form inside account tab’ is closed to new replies.