Hot answers tagged

25 votes
Accepted

$_POST form request with admin-post

Maybe a little late but I stumbled on this when I was having issues figuring it out so thought I would supply what I found out for future people. I've found the basic principles are to have a hidden ...
user avatar
  • 366
19 votes
Accepted

how to set from address according to the form input email address for wp_mail()?

If I'm understanding you right you just are having trouble getting the from set? The easiest way would just be adding the from in the email headers in the wp_mail function. Here is an example of one ...
user avatar
13 votes

WordPress AJAX File Upload - FrontEnd

Hi You have Use this COde For WordPress front-end AJAX file upload tutorial Code Here is my code: In my template file example.php <form enctype="multipart/form-data"> <input type="text" ...
user avatar
12 votes

What is the real intention for admin-post.php?

admin-post.php is like a poor mans controller for handling requests. It's useful in the sense that you don't need to process your request on an alternative hook such as init and check to see whether ...
user avatar
  • 16k
11 votes
Accepted

Is wp_nonce_field vulnerable if you know the action name?

Short answer: No. You can use normal strings for actions, md5'ing them doesn't change anything. The nonce is built from three main pieces of information: Time: The current time() divided by 43200 is ...
user avatar
  • 32.1k
11 votes
Accepted

admin-ajax.php doesn't work when using POST data and Axios

The issue here, I think, is how axios works. Not WordPress. But you're absolutely correct to want to use a POST request here. By default I believe axios sends data in a POST request as JSON in the ...
user avatar
10 votes
Accepted

How to HTML5 FormData Ajax

The action should be part of the data object: var formdata = new FormData(); formdata.append('name', 'This is Name'); formdata.append('action', 'plugin_save'); $.ajax({ url: 'admin-ajax.php', ...
user avatar
  • 76.2k
10 votes
Accepted

Hide the term description on the term edit page, for a given taxonomy

You could target the edit form for the post_tag taxonomy, through the post_tag_edit_form hook: /** * Hide the term description in the post_tag edit form */ add_action( "post_tag_edit_form", ...
user avatar
  • 64.1k
9 votes

Why when I submit a form in wordpress it loads a 404 page though URL is correct

It is no only name or email problem, as Tom wrote. I had problem even with input field with name attribute same as one of my Custom Post Types. For example: ... <input type="text" name="movie">...
user avatar
  • 877
8 votes

How do we remove the H3 tag for the reply-title I.D

Today there is a native option to do this without hacking the core, or doing tricky filters with output buffer. You just need to use the filter 'comment_form_defaults' and edit the values from '...
user avatar
8 votes
Accepted

Get selected values from checkboxes and radio buttons via Gravity Forms gform_after_submission hook

If you have the form/field object you can retrieve a comma separated string containing the fields selected choices by using the GF_Field::get_value_export() method which was added in Gravity Forms 1.9....
user avatar
8 votes
Accepted

Contact Form 7 Custom Post Action

As per the CF7 Documentation, you can disable AJAX form submission by placing the following code in your wp-config.php define('WPCF7_LOAD_JS', false);
user avatar
  • 468
8 votes
Accepted

How to call WordPress functions from a form processing script

You should never post anything to plugins files directly. It's almost always a security flaw and it prevents site owner from hardening the site properly (in perfect situation no requests to PHP files ...
user avatar
7 votes

how to set from address according to the form input email address for wp_mail()?

For this filtering the email address: add_filter( 'wp_mail_from_name', 'my_mail_from_name' ); function my_mail_from_name( $name ) { return "My Name"; } Now add a filter for the name of the email ...
user avatar
7 votes

Inserting data into custom tables

You said your form is in the main folder? I guess you need to set proper URL for action="". You could try: action="<?php echo site_url() . '/setLiquorType.php'; ?>" It is ...
user avatar
  • 171
7 votes

Custom Form with Ajax

Your attempt to send your AJAX requests to wp-admin/admin-ajax.php is correct but it will be better to create a javascript global variable using wp_localize_script() to make any data available to your ...
user avatar
  • 71
7 votes
Accepted

Get post ID from wp_insert_post()

You'll have to do this in two steps. First, you will create a post in the draft mode, using wp_insert_post(). The wp_insert_post itself will return to you the ID of the inserted post: <?php $...
user avatar
7 votes
Accepted

Why is there a class="screen-reader-text" on my search button?

This class is used to visually hide elements from sighted users but still allows assistive technologies like screen readers to still present those elements to users who are visually impaired. For ...
user avatar
  • 1,589
7 votes

How to get current url in contact form 7

See this example on how to create and parse the shortcode in the contact form 7 to use it add [current_url] add_action( 'wpcf7_init', 'wpcf7_add_form_tag_current_url' ); function ...
user avatar
  • 1,723
7 votes

How to disable autocomplete for inputs in contact form 7?

According to the question and answer from the developer placed here: https://wordpress.org/support/topic/autocomplete-off-3/ You just need to add the autocomplete:off option to the shortcode: [email ...
user avatar
  • 545
6 votes

Hide the term description on the term edit page, for a given taxonomy

The cleanest way to do that, removing the description field from the edit screen also in the add screen: function hide_description_row() { echo "<style> .term-description-wrap { display:...
user avatar
6 votes

contactform7 remove tags with "wpcf7_autop false" from functions.php

If you have already upgraded CF7 to version 5.0 or higher, then you can use the new hook: add_filter( 'wpcf7_autop_or_not', '__return_false' );
user avatar
6 votes

Get post ID from wp_insert_post()

Check the documentation: Return: (int|WP_Error) The post ID on success. The value 0 or WP_Error on failure. Thus: $result = wp_insert_post( $data ); if ( $result && ! is_wp_error( $...
user avatar
  • 35.6k
6 votes
Accepted

How to exclude pages from the search results

Note that when we use: $query->set( 'post_type', 'post' ); then we're overriding all searchable post types, not only the page post type. That may be just fine in some cases, and we're done ...
user avatar
  • 64.1k
6 votes
Accepted

How to handle a custom form in wordpress to submit to another page?

<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post"> <input type="hidden" name="action" value="your_action_name"> Add these in your form. Where admin-...
user avatar
5 votes

Creating wordpress user registration form

You are sending the data from the form directly to TestForm.php file, which is a PHP script outside of WordPress logic. It is and independent script. You could set the form's action attribute to a ...
user avatar
  • 19.8k
5 votes

$_POST form request with admin-post

Before redirecting you can save any validation errors and post values into a transient. These values will persist after the url redirection. This is exactly how WP core does it for the Settings API ...
user avatar
5 votes
Accepted

How to add and submit input fields using a shortcode?

You can create the shortcode like this: add_shortcode( 'add_fields', 'input_fields' ); function input_fields( $atts ) { if ( isset( $_POST['gg'] ) ) { $post = array( '...
user avatar
  • 181
5 votes
Accepted

Gravity Forms skip form if already filled out using cookie?

Here's some code on how you could simply leverage the gform_after_submission hook of Gravity Forms to set a cookie based on your form ID once submitted, then check for that on the confirmation page by ...
user avatar
5 votes
Accepted

Genesis - Customize search form

I'm not sure why you're getting a 500 error. Likely because you're trying to use a function before it's been defined. But I think you're going about the problem the wrong way. Genesis does provide a ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible