Duplicating/Cloning Multiple Form Fields

Instead of looking for a plugin I found a piece of code that solves my problem, unfortunately because I am not using a plugin this post doesn’t relate to WordPress and is off-topic. For those of you who are curious the code I am using is at: http://charlie.griefer.com/blog/2009/09/17/jquery-dynamically-adding-form-elements/ <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” … Read more

Setting specific image size for specific form upload file field

Here’s an example of how to unset the standard WordPress sizes or any size for that matter assuming you know the image size name and of course you can simply inpect the $sizes array to determine what to unset… function wpse219360_disable_intermediate_image_sizes($sizes) { if ( isset($_FILES[‘file_input_1’]) && $_FILES[‘file_input_1’][‘error’] != UPLOAD_ERR_NO_FILE ) { unset($sizes[‘thumbnail’]); unset($sizes[‘medium’]); unset($sizes[‘large’]); } … Read more

Help with verifying google recaptcha in a custom form

You need to validate the reCAPTCHA immediately once you POST the form. You’re just sending a POST to the same page, so it should be done before any other handling. If it does not validate, you need to show the form again, with an error message. function recaptcha_validated(){ if( empty( $_POST[‘g-recaptcha-response’] ) ) return FALSE; … Read more

How to return variables from admin-post.php

You can send GET variables in the URL using wp_redirect. For example: wp_redirect( home_url() .’/form?result=error&reason=3′); As far as I know, yes, admin-post is the best-practices way to handle POST data in WordPress.

Looking for a simple approach for handling user $_POST data without AJAX?

The best way to process the custom form is the following. If you are using nonce then you don’t really have to check $_POST[‘checkbox’], the code below can be used simply to verify_nonce and then process the form. function process_my_form() { if ( wp_verify_nonce( $_POST[‘my_nonce_field’], ‘my_nonce’ ) ) { // process your form here // … Read more

One comment per user per post

Simply add the post_id parameter to the get_comments arguments array something like: global $current_user,$post; $args = array(‘user_id’ => $current_user->ID,’post_id’ => $post->ID); $usercomment = get_comments($args); if(count($usercomment) >= 1){ echo ‘disabled’; } else { comment_form(); }

Checkbox won’t check when label is clicked

Okay, so in case this is of use to anyone else. The original checkbox hack tut that I was following came from here. I’ve got around the issue that I was having in WordPress by wrapping my checkboxes in the labels like <label><input id=”fieldjtdktry-0″ name=”cm-fo-jtdktry” value=”4469820″ type=”checkbox” /><span></span>Learn</label> and then just tweaking the CSS selector … Read more