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.
Does your form have an input with the name “name”? For example:
If so, that will cause trouble. Change the name value.
Also see: Form ‘name’ breaks and goes to 404 page.
I’m assuming that the line near the end
wp_redirect( get_permalink(35) );//page that has form
is what is failing. I would change it to this
that should cause it to function to work properly
I take
die()
as solution. Though, I don’t prefer this.