简体   繁体   English

如何为 PHP 自定义我自己的状态消息? [等候接听]

[英]How Do I Customize My Own Status Messages for PHP? [on hold]

When I am at other websites and I create a new account, I get an alert style dialog box telling me if my info was successfully sent, while staying on the same webpage I created my account on.当我在其他网站上创建新帐户时,我会看到一个警报样式对话框,告诉我我的信息是否已成功发送,同时停留在我创建帐户的同一网页上。 That dialog box has an "OK" button to select that closes the dialog box and resets the HTML form back to empty fields.该对话框有一个指向 select 的“确定”按钮,用于关闭对话框并将 HTML 表单重置为空字段。

I want to do this on my website.我想在我的网站上这样做。 Currently, I have an HTML form that captures email addresses.目前,我有一个 HTML 表单,它捕获 email 地址。 When I click SUBMIT, the PHP file takes the email address, verifies the email, uploads it into mysql, then opens a new browser window echoing the status of the PHP processes that were just run. When I click SUBMIT, the PHP file takes the email address, verifies the email, uploads it into mysql, then opens a new browser window echoing the status of the PHP processes that were just run.

I do not want PHP opening a browser window where it displays the status of the processes.我不希望 PHP 打开浏览器 window 显示进程状态。 I simply want a dialog box to open in the same webpage that the form is on stating that the email address was successfully uploaded, or not successfully uploaded, or that the email address is invalid.我只是想在表单所在的同一网页中打开一个对话框,说明 email 地址已成功上传,或未成功上传,或者 email 地址无效。 Either way, no opening a second window, and an alert style dialog box that displays the status with an "OK" button to close the dialog box, and reset the form with blank fields.无论哪种方式,都不会打开第二个 window 和一个警报样式对话框,该对话框显示状态,带有“确定”按钮以关闭对话框,并使用空白字段重置表单。

I have spent 2 days searching the internet with various wording and I have explored the library here, but I cannot find help on this.我花了 2 天时间在互联网上搜索各种措辞,并在这里探索了图书馆,但我找不到这方面的帮助。

I am thinking my question has a standard solution because this is how most websites work when starting an account.我认为我的问题有一个标准解决方案,因为这是大多数网站在开设帐户时的工作方式。 I have probably been using incorrect terminology when searching.我可能在搜索时使用了不正确的术语。 Here is my php code to upload the HTML form data into mysql:这是我的 php 代码,用于将 HTML 表单数据上传到 mysql:

<?php

    //MySQL/MariaDB connection block with the server location (localhost), the database name, and the database username and password.

    $email_a = $_POST['emailDesktop'];
    $email_b = $_POST['emailVerifyDesktop'];

    if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
        echo "Email address '$email_a' is considered valid.\n";
}
    if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
        echo "Email address '$email_b' is considered valid.\n";
}   else {
        echo "Email address '$email_b' is considered invalid.\n";
}


    $hostname = "xxxxxxxxxxxxxx";
    $username = "xxxxxxxxxxxxxx";
    $password = "xxxxxxxxxxxxxx";
    $db = "xxxxxxxxxxxxxx";

    //Then we add a section to connect to the database, and give an error if the connection fails:

    $dbconnect=mysqli_connect($hostname,$username,$password,$db);

    if ($dbconnect->connect_error) {
      die("Database connection failed:" .$dbconnect->connect_error);
    }


    //Next, we "translate" the data from the HTML form into PHP variables:

    if(isset($_POST['submit'])) {
        $emailDesktop=$_POST['emailDesktop'];




        //Then insert this information into the database:

        $query = "INSERT INTO members (emailDesktop)
        VALUES ('$emailDesktop')";


        //Add a nested if statement which will give an error message if the process fails, or thank the user for their review if it succeeds:

        if (!mysqli_query($dbconnect, $query)) {
        echo 'An error occurred when submitting.';
        } else {
        echo 'Upload successful.';


        }
    }

You can use ajax to submit your form data to the server and a modal to alert the end-user about the response.您可以使用 ajax 将您的表单数据提交到服务器,并使用模式来提醒最终用户有关响应。

The following code is an example of submitting data via ajax, using jQuery :以下代码是通过 ajax 提交数据的示例,使用jQuery

$("button").click(function(){
  $.ajax({
    url: "verify_email.php",
    data: your_data,
    success: function(result){
      showalert(result);
    }
  });
});

Refer to w3schools to learn how to make a CSS/JS modal.请参阅w3schools以了解如何制作 CSS/JS 模态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM