I have a frontend form with a bunch of input. My requirements force me to use a custom shortcode to create the form. I have already tested a page with that shortcode.
Here’s my :
<form name="myform" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>" enctype="multipart/form-data">
Based on this, it should open up the same page (and it did). However, when I hit submit, I got 404 on that very same URL. Is there any solution?
UPDATE #1
I try different route, using add_action(‘init’):
add_action('init', 'mbro1_intercept_form_input');
function mbro1_intercept_form_input()
{
if( !(isset($_POST['action_code']) && $_POST['action_code'] == 'mbro_intercept_form_input') )
return "";
if( isset( $_POST['submit'] ) )
{
//do my code here
wp_redirect( get_permalink(35) );//page that has [shortcode]
}
}
This successfully run my intended action on submit. But! upon redirection, it still got 404. I don’t know what is wrong.
3 Answers
Does your form have an input with the name “name”? For example:
<input type="text" name="name">
If so, that will cause trouble. Change the name value.
Also see: Form ‘name’ breaks and goes to 404 page.