提交表单后将页面重定向到另一页面

时间:2014-04-10 17:50:08

标签: php

我需要在提交表单后将用户重定向到新页面。我搜索了很多主题,但我无法让我的表单上班。 header("Location: http://www.example.com/");该邮件就像表单一样,但您不会登陆example.com网站。提前谢谢!

这就是我的代码的样子。

function nice_contact_ajax() {

    global $nice_options;

    check_ajax_referer( 'play-nice', 'nonce' );

    if( !empty( $_POST ) ) {

        $admin_email = get_option( 'nice_email' );

        if ( trim( $admin_email ) == '' )
            $admin_email = get_bloginfo( 'admin_email' );

        $mail = $_POST['mail'];
        $voornaam = $_POST['voornaam'];
        $achternaam = $_POST['achternaam']; 
        $bedrijfsnaam = $_POST['bedrijfsnaam'];
        $telefoonnummer = $_POST['telefoonnummer'];
        $plaats = $_POST['plaats']; 
        $aantalusers = $_POST['aantalusers'];   
        $abonnement  = 'Geen offerteaanvraag';
        if(isset($_POST['abonnement']) && is_array($_POST['abonnement']) && count($_POST['abonnement']) > 0){
            $abonnement = implode(', ', $_POST['abonnement']);
        }

        $body .= 'Gekozen abonnementen: ' . $abonnement;


        $error = "";

        if( !$voornaam ) {
            $error .= __( 'Vertel ons alstublieft uw voornaam','nicethemes' ) . "<br />";
        }
        if( !$achternaam ) {
            $error .= __( 'Vertel ons alstublieft uw achternaam','nicethemes' ) . "<br />";
        }
        if( !$mail ) {
            $error .= __( 'Vertel ons alstublieft uw e-mailadres','nicethemes' ) . "<br />";
        }
        if( !$plaats ) {
            $error .= __( 'Vertel ons alstublieft uw woonplaats','nicethemes' ) . "<br />";
        }
        if( !$bedrijfsnaam ) {
            $error .= __( 'Vertel ons alstublieft uw bedrijfsnaam','nicethemes' ) . "<br />";
        }
        if( !$telefoonnummer ) {
            $error .= __( 'Vertel ons alstublieft uw telefoonnummer','nicethemes' ) . "<br />";
        }



        if( empty( $error ) ) {

            $mail_subject = '[' . get_bloginfo( 'achternaam' ) . '] ' . __( 'U heeft een nieuw bericht vanaf het formulier van uw website','nicethemes' );

            $body = __( 'Voornaam: ', 'nicethemes' ) . "$voornaam \n\n";
            $body = __( 'Achternaam: ', 'nicethemes' ) . "$achternaam \n\n";
            $body = __( 'Plaats: ', 'nicethemes' ) . "$plaats \n\n";
            $body = __( 'Bedrijfsnaam: ', 'nicethemes' ) . "$bedrijfsnaam \n\n";
            $body = __( 'Telefoonnummer: ', 'nicethemes' ) . "$telefoonnummer \n\n";        
            $body = __( 'Email: ', 'nicethemes') ."$mail \n\n";
            $body = __( 'Aantal Users: ', 'nicethemes' ) . "$aantalusers \n\n";
            $body .= __( 'Offerteaanvraag voor type abonnement(en): ', 'nicethemes' ) . "$abonnement \n\n";

            $body = __( 'Voornaam: ', 'nicethemes' ) . "$voornaam \n\n"
            . __( 'Achternaam: ', 'nicethemes' )  ."$achternaam \n\n" 
            . __( 'Email: ', 'nicethemes') ."$mail \n\n" 
            . __( 'Plaats: ', 'nicethemes' )  ."$plaats \n\n"
            . __( 'Bedrijfsnaam: ', 'nicethemes' )  ."$bedrijfsnaam \n\n"
            . __( 'Telefoonnummer: ', 'nicethemes' )  ."$telefoonnummer \n\n"
            . __( 'Aantal Users: ', 'nicethemes' ) . "$aantalusers \n\n"
            . __( 'Offerteaanvraag voor type abonnement(en): ', 'nicethemes' ) . "$abonnement \n\n";

            $headers[] = __( 'Van: ', 'nicethemes' ) . $achternaam . ' <' . $mail . '>';
            $headers[] = __( 'Beantwoord: ', 'nicethemes' ) . $mail ;
            $headers[] = "X-Mailer: PHP/" . phpversion();

            if( $sent = wp_mail( $admin_email, $mail_subject, $body, $headers ) ) {
                _e( 'Bedankt voor uw bericht', 'nicethemes' );
                header("Location: http://www.example.com/");
            }else {
                _e( 'Er ging iets fout, probeer het opnieuw', 'nicethemes' );
            }

        } else {
            echo $error;
        }
    }
    die();
}

这是Ajax函数:

submitHandler: function(form) {

                var str = jQuery('#nice_contact').serialize();

                jQuery.ajax({
                    type: "POST",
                    url: "<?php echo admin_url();?>admin-ajax.php",
                    data: 'action=nice_contact_form&nonce=<?php echo wp_create_nonce("play-nice");?>&' + str,
                    success: function(msg) {
                        jQuery("#node").ajaxComplete(function(event, request, settings){
                                if(msg == 'sent') {
                                    jQuery(".nice-contact-form #node").hide();
                                    jQuery(".nice-contact-form #success").fadeIn("slow");
                                    jQuery("#nice_contact input[type=text], #nice_contact textarea").val("");
                                }else {
                                    result = msg;
                                    jQuery(".nice-contact-form #node").html(result);
                                    jQuery(".nice-contact-form #node").fadeIn("slow");
                                }
                        });
                    }
                });
                return false;
                form.submit();

            }

0 个答案:

没有答案
相关问题