WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


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.

share|improve this question
Whats your form code? – Bainternet Apr 28 '11 at 9:14
@bainternet here: pastebin.com/fXvyuwnx – ariefbayu Apr 28 '11 at 9:22

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.

share|improve this answer
I don't have 'name' on my form. – ariefbayu Apr 28 '11 at 6:40

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

$redirect_link =  get_permalink(35) ; //page that has form
wp_redirect( $redirect_link );  // trigger redirect

that should cause it to function to work properly

share|improve this answer
it doesn't work either T_T – ariefbayu May 1 '11 at 22:19
What is the 404 link, in specific? i.e. what's the URL of the page it's trying to redirect to and thus 404ing on? – Norcross May 2 '11 at 0:29
it come from example.com/?page_id=35 and on submit, it goes to example.com/?page_id=35. After process, it should redirect to example.com/?page_id=35 so that when user hit refresh, it doesn't have any effect to site. – ariefbayu May 2 '11 at 1:13
ups, wrong click. Well, it's your lucky day to get +50 reps ;)) – ariefbayu May 2 '11 at 4:18
up vote 0 down vote accepted

I take die() as solution. Though, I don't prefer this.

$redirect_link =  get_permalink(35) ; //page that has form
$script_redirect = "<div>Your form is submitted. Please wait a moment. If your browser didn't redirect, click <a href='$redirect_link'>here</a>.</div>
<script type='text/javasript' language='javascript'> 
    window.location = '$redirect_link';
</script> ";
die( $script_redirect );
share|improve this answer
Does it work if you add the die() after your call to wp_redirect()? Just calling the redirect does not stop script execution. You see this pattern in the core code too: wp_redirect( $somewhere ); exit;. – Jan Fabry May 4 '11 at 15:27
We'll somehow it work. I did try wp_redirect(); exit; Weird, right? – ariefbayu May 4 '11 at 22:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.