4

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.

0

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.

  • I don't have 'name' on my form. – ariefbayu Apr 28 '11 at 6:40
0
+50

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
exit;

that should cause it to function to work properly

  • 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
  • 1
    ups, wrong click. Well, it's your lucky day to get +50 reps ;)) – ariefbayu May 2 '11 at 4:18
0

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 );
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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