首页 > 解决方案 > 我的第一个联系表单插件中的 success.php 导致找不到页面

问题描述

更新:对不起,感谢您提供的解决方案......不太清楚如何实施,我想我不太清楚......如果我能理解如何实施解决方案,那将是整洁的......

我还成功地设法让代码工作以创建一个新的数据库表并插入测试数据,但忽略了这一点,所以它并不那么复杂......

我真的很想能够...

也许在发送消息后有更好的方法来重定向用户......

然后....我还需要将表单数据(尚未完成)保存到我创建的新表(通过插件创建表),然后在管理面板中显示所有表单提交记录的表(不是完毕)

所以我的includes/webform.php 很好地显示了它发送电子邮件的表单,但我无法通过success.php 或error.php 获得此错误或成功消息。

我想这是我错的地方

   function deliver_opp_mail() {
       // if the submit button is clicked, send the email
   if ( isset( $_POST['d6s-submitted'] ) ) {

    //sanitise form values so that form data is readable... eg/ if users enter code/script or formatting symbols, it is not missinterpretted as code and is seen as all text. 
    $name    = sanitize_text_field( $_POST["d6s-opp-name"] );
    $email   = sanitize_email( $_POST["d6s-opp-email"] );
    $messagesubject = sanitize_text_field( $_POST["d6s-opp-subject"] );
    $messagecontent = esc_textarea( $_POST["d6s-opp-message"] );
    $phone = ( $_POST["d6s-opp-phone"] );
                //  Would like to consider calling form values via global Variables. 

    $subject = "NEW OPPURTUNITY: $messagesubject";

    $d6sdir = plugin_dir_path( __FILE__ );

    //Create the Email Body Message using free text and data from the form.  
    $message = "New Message From: $name \n MESSAGE: $messagecontent \n Return Email: $email \n Return Phone $phone ";


    // get the blog administrator's email address, form data is emailed to this email address.  
    $to = get_option( 'admin_email' );
            // Look into setting a to: Email address in WP Admin Console. 

    $headers = "From: $name <$email>" . "\r\n";

    if ( wp_mail( $to, $subject, $message, $headers ) ) {

    //maybe this is in the wrong spot, or perhaps this is not the solution I need, but I have tried this in a few different places and can't get it to work.. 
        $Msg = array(
            "You have an error",
            "Your mail sent succesfully"
        );

        $_SESSION['errMsg'] = $Msg;

    //this take the user to www.mydomain.com/.....wp-content/plugins/my-plugin/includes/success.php - the file is there, but WP theme not found is displayed. 

 header("Location: $d6sdir/success.php");
exit;
   }
   }
   }
   ?>

*不想在表单上方显示成功或错误消息...未来的工作流程计划需要在用户点击提交后将用户带到没有表单和其他内容的页面。

*也使用错误报告 - 在显示未找到主题位之前似乎发生了某些事情或闪烁,并且没有报告其他错误......

    <?Php  error_reporting(E_ALL); ini_set('display_errors', 1);

****************************** 来自初始帖子.... 真的很想学习。第一次发帖,感谢帮助

插件的目的:创建一个插件,我最终可以为我的小型企业构建一个自定义 CRM 工具并学习编码。

*为什么这么不简单...

标签: phpwordpresscontact-formfile-not-found

解决方案


解决方案 1将消息传递给success.php

$Msg = array(
    "You have an error",
    "Your mail sent succesfully"
);
$_SESSION['errMsg'] = $Msg;

success.php 

$Errors = implode(' ', $_SESSION['errMsg']);
echo $Errors;

解决方案 2:

$_SESSION["errMsg"] = "Your mail sent succesfully";

if(isset($_SESSION['errMsg']) AND !empty($_SESSION['errMsg']) ): 
echo "<div class='alert danger'>".$_SESSION['errMsg']."</div>"; 
endif;

未找到解决方案:

您可以使用$_SERVER['DOCUMENT_ROOT'];查找根D:/wamp/www

然后是页面的完整网址,如下所示:

echo $_SERVER['DOCUMENT_ROOT']."/yourFolder/test.php";

输出 :D:/wamp/www/yourFolder/test.php

注意exit();:如果你在之后使用会很好header("Location:");


推荐阅读