[success.php在我的第一个联系表单插件中未找到页面的结果

问题描述 投票:0回答:1

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

我也成功地设法使代码可以工作以创建新的数据库表并插入测试数据,但是忽略了它,所以它并不那么复杂。...

我真的很想能够...

  • 显示成功发送消息后可以放入success.php(或其他位置)的一些内容该内容将显示“消息已发送-是!然后我想能够添加,存在wp内容-您可能感兴趣的某些服务或产品,并在消息发送后在同一成功结果页面上显示它们...

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

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

  • 我替换了main.php文件的内容(插件名称为root的插件的主php文件。

    <?php
    /** template info etc...
    **/
    // Find all .php files in the includes dir of my plug in folder. 
    foreach ( glob( plugin_dir_path( __FILE__ ) . "includes/*.php" ) as $file ) {
    include_once $file;
    } 
    ?>
    
  • 和我的所有文件,除了主要文件(位于插件根目录)外,都在plugins / plugin-name / includes中,并且可以找到-呀

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

  • [includes / success.php现在看起来像这样……根据DK的建议

    <?Php
    $Errors = implode(' ', $_SESSION['errMsg']);
    echo $Errors; ?>
    
  • includes / webform.php现在看起来像这样...

    <?php
    
    function d6s_opp_html_form() {
    echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
    
     //Form action page is the current url.  the form is called by a shortcode that will run functions that are written within this plugin's files, they can be in different files in different folders within the plug in because we have told the plug in to load them in the main plug in file.php horray thay is working..     
    
    // other form fields removed to shorten this stakoverflow post 
    echo '<p>';
    echo 'Your Name* <br />';
    echo '<input type="text" name="d6s-opp-name" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["d6s-opp-name"] ) ? esc_attr( $_POST["d6s-opp-name"] ) : '' ) . '" size="40" placeholder="First & Last name" required />';
    
    // Now using required - is that better than having to check if not empty in success or fail bit????
    
     echo '<p><input type="submit" name="d6s-submitted" value="Send"/></p>';
     echo '</form>';
    }
    
    //Short code function is here and works GREAT
    
  • 然后在同一文件中,这是我认为DK意味着我应该将其解决方案1的第一部分放在其中的功能]]

  • [我猜这是我仍然有错的地方

   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工具中,并学习编码。

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

更新:对不起,感谢您提供的解决方案。。。我还不太清楚如何实施,我想我不太清楚。。。如果我能理解如何实施简洁的解决方案,我也可以.. 。

php wordpress contact-form file-not-found
1个回答
0
投票

解决方案1

将消息传递到success.php
© www.soinside.com 2019 - 2024. All rights reserved.