Articles of forms

Custom form handling in WP.. the correct way?

What is the best way to process a form in WP using correct design patterns? I am finding a lot of outdated and inconsistent information online and the way I am doing it now is not sustainable. At the moment, when I am doing some heavy PHP work (ie.. processing large forms) I tend to […]

A function that will remove HTML <div> and </div> tags from a string?

I need a function that I can use that will remove <div> and </div> tags from a string. I have tried esc_attr(), and even wp_strip_all_tags() — none of them work. They all leave the <div> and </div> tags in the string – which causes certain social-media buttons to turn out in ways that really do […]

Reason action hook won't work with update_post_meta from frontend form? Alternative?

The code below works when I am inserting a post/using add_post_meta when submitting a form. The page refresh is flawless (see How can I fix a slow redirect after form submit from frontend (no plugin)?). However, I can’t seem to get the same effect when using forms that I intend to update the post meta […]

How can I fix a slow redirect after form submit from frontend (no plugin)?

Below is the code I’m using for my short-coded form and to add the post. Here’s a basic overview of the problem I’m trying to remedy: -This form is displayed on the page at /addmember/ -On this page is also a list of existing members, current and pending (members being a custom post type) -This […]

How to add the post ID (or any other post data) to a Contact Form 7 mail?

I’ve downloaded Contact Form 7 to add contact forms adding a simple snippet after every post, and I’ve added it in functions.php like this : //if post type I add a form function is_post_type($type) { global $wp_query; if($type == get_post_type($wp_query->post->ID)) return true; return false; } function add_post_content($content){ if(!is_feed() && !is_home()&& is_single() && is_post_type(‘post’)) { $content […]

How to have multiple instances of the same taxonomy in a search form

I’m trying to have two separate search fields for tags on a search page on my WordPress site, but it seems have a duplicate instance of a taxonomy breaks the search functionality. <form method=”get” id=”search form” action=”/”> <div> <input type=”text” value=”” name=”tag” id=”tag” /> <input type=”text” value=”” name=”tag” id=”tag” /> <input type=”hidden” value=”94″ name=”cat” id=”scat” […]

form $_post action value gets truncated after it passes through two forms

There are three pages page1, page2 and page3. When I press submit on my first form on page 1 my group name field can be catched with $_POST[‘groupname’] in the destination page but in the page 2 I have another form which when pressed should pass the value of $_POST[‘groupname’] to third page. On third […]

Ajax image upload with media_handle_upload and form.js

I want to have AJAX image upload on front-end form and can’t figure out where it goes wrong. HTML form for image upload <form id=”thumbnail_upload” method=”post” action=”#” enctype=”multipart/form-data” > <input type=”file” name=”thumbnail” id=”thumbnail”> <input type=’hidden’ value='<?php wp_create_nonce( ‘upload_thumb’ ); ?>’ name=’_nonce’ /> <input type=”hidden” name=”action” id=”action” value=”my_upload_action”> <form> <div id=”output1″></div> <script> jQuery(document).ready( function($) { //http://wordpress.stackexchange.com/questions/72406/set-featured-image-front-frontend-form […]

Duplicate “default” form with jQuery

I have this code: // Add form jQuery(‘.add-form’).click(function() { // “Copy” default form formGroup = jQuery(‘.form-item’).html(); // “Paste” default form jQuery(‘#main-form’).append(‘<div class=”form-item row”>’+formGroup+'</div>’); }); Situation: There’s a form by default If you press the button, this code runs It duplicates default form & place it under default form If pressed again, it makes third form […]

Submit form to a different PHP file in the same plugin folder

I want to submit a form to another PHP file which lays in the same folder: wp-content/plugins/my-plugin-folder The form action attribute looks like this: <form name=”lookat” type=”submit” action=”my-plugin-folder/file.php”> However, if I click on the submit button, I get redirected to: http://localhost/wordpress/wp-admin/my-plugin-folder/file.php How can I get rid of wp-admin and access the file in my-plugin-directory?