如何使用PHP函数include_once()在其他目录中提交表单?

时间:2017-12-04 19:11:57

标签: javascript php jquery html debugging

请为我的理解提供临时解决方案和深度相关的答案。 我有一个名为/ users / with signup.html和/users/js/signup.js和/users/signup.php的目录

在我的主页上,我使用php:include_once(signup.html)然后当我点击注册按钮时,它会使用index.php目录中的目录。

是否有一个有效包含在signup.html文件路径中的函数?

/public_html/index.php

/public_html/users/signup.html

<!DOCTYPE html>

<html>

<head>

    <title>Sign Up</title>

    <meta charset="UTF-8"><br>


    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

</head>

<div class="container py-5">
    <div class="row">
        <div class="col-md-12">
            <h2 class="text-center text-white mb-4">Bootstrap 4 Login Form</h2>
            <div class="row">
                <div class="col-md-6 mx-auto">
                    <span class="anchor" id="formLogin"></span>

                    <div id="signupStatus"></div>
                <!--Card Sign Up !-->
                <div class="card rounded-0">
                    <div class="card-header">
                        <h3 class="mb-0">Sign Up</h3>
                    </div>
                    <div class="card-body">

                        <form id="signupForm" class="form" role="form" autocomplete="off" style="overflow: hidden">

                            <div class="signup form-group">
                                <label for="username">Username</label>
                                <input type="text" id="username" class="form-control form-control-lg rounded-0" name="username" placeholder="username"/>
                            </div>

                            <div class="signup form-group">
                                <label for="email">Email</label>
                                <input id="email" class="form-control form-control-lg rounded-0"  type="email" name="email" placeholder="email"/>
                            </div>

                            <div class="signup form-group">
                                <label for="password">Password</label>
                                <input id="password" class="form-control form-control-lg rounded-0"  type="password" name="password" placeholder="password"/>
                            </div>

                            <div class="signup"><input class="btn btn-success btn-lg float-right" type="button" id="signup" value="Sign up"/></div>

                            <div class="signup"><a href="http://woofwarrior.com/users/login.html">...already a user?</a></div>

                        </form>
                    </div>
                </div>
            </div>

</div>
        </div>
    </div>
</div>







<script type="text/javascript">


    users_dir = 'http://'+window.location.hostname+'/users/';




document.getElementById("signup").onclick = function(){

    var httpRequest;

    httpRequest = new XMLHttpRequest();



    if (!httpRequest) {

        console.log('Cannot create an XMLHTTP instance');

        return false;

    }else{

        httpRequest.onreadystatechange = alertContents;


        var formElement = document.getElementById('signupForm');

        var formData = new FormData(formElement);

        httpRequest.open("POST", users_dir+'signup.php');

        //console.log(formData);

        httpRequest.send(formData);

    }

    function alertContents() {

        if (httpRequest.readyState === XMLHttpRequest.DONE) {
            //console.log(httpRequest.status);

            if (httpRequest.status === 200) {

                //console.log("test123");

                var data = JSON.parse(httpRequest.responseText);

                //console.log(data);

                document.getElementById('signupStatus').innerHTML = data;

            }else{

                console.log('There was a problem with the request.');

            }

        }

    }

}

1 个答案:

答案 0 :(得分:0)

<a href="<? $_SERVER['DOCUMENT_ROOT'].'/users/signup.html' ?>">click</a>

这是你要问的吗?