• I am building a simple step form (step1 -> step2 -> step3)

    At the first page, I did like this.

    if( isset($_POST['step1']) ) {
    
                            include_once( get_template_directory() . '/includes/form2.php' );
    
                        } elseif( isset($_POST['step2']) ) {
    
                            include_once( get_template_directory() . '/includes/form3.php' );
    
                        } else {
    
                            include_once( get_template_directory() . '/includes/form1.php' );
    
                        }

    Each form pass value like this.

    <form name="mainform" id="mainform" class="form_step" action="" method="post">
    <input type="submit" name="step1" id="step1" class="btn_orange" value="<?php _e( 'Continue ››', APP_TD ); ?>" />

    on Step1, agreement page,
    But on Step2, input form for title, content, tags (real input form page)
    then it goes to a function to save values like this.
    (after save values, I need to move Step3 with several values such as post_id which just saved and name, price

    //*************************************************************************************//
    if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
    
    // Do some minor form validation to make sure there is content
    if (isset ($_POST['title'])) {
        $title =  $_POST['title'];
    } else {
        echo 'Please enter a title';
    }
    if (isset ($_POST['description'])) {
        $description = $_POST['description'];
    } else {
        echo 'Please enter the content';
    }
    $tags = $_POST['post_tags'];
    $step2 =  $_POST['step2'];
    
    // Add the content of the form to $post as an array
    $post = array(
        'post_title'    => $title,
        'post_content'  => $description,
        'post_category' => $_POST['cat'],  // Usable for custom taxonomies too
        'tags_input'    => $tags,
        'post_status'   => 'publish',           // Choose: publish, preview, future, etc.
        //'post_type'   => $_POST['post_type']  // Use a custom post type if you want to
        'post_type' => 'us_step'
    );
    wp_insert_post($post);  // Pass  the value of $post to WordPress the insert function
                            // http://codex.wordpress.org/Function_Reference/wp_insert_post
    //wp_redirect( home_url() );
    
    echo "ok=". $step1;
    echo "ok=". $step2;
    echo "ok";
    
    //wp_redirect( 'http://domain.com/' );
    //wp_redirect( 'http://domain.com/thanks-page/', 301 ); exit;
    $step2 =  $_POST['step2'];
        $name =  $_POST['name'];
        $price =  $_POST['price'];
        $post_id = $_POST['postid'];
    
    wp_redirect( 'http://domain.com/step-form/', 301, $step2='yes' );
    exit;
    } // end IF
    
    // Do the wp_insert_post action to insert it do_action('wp_insert_post', 'wp_insert_post');
    
    ?>

    I need to make it move to STEP 3 with $name, $price, $post_id But wp_redirect does seem to bring values (arguments) How can I fix it to move them to Step3?

    By the way, How can I get the “post id” after it gets saved on function?

    Thanks,

  • The topic ‘For Multi form, how to pass values and get post-id’ is closed to new replies.