jscript表单行动不起作用

时间:2014-09-26 22:57:37

标签: php jscript

在我编写动态包含系统之前,这些表单正在运行。我chesed jscripts目录但似乎没有工作... CSS样式正在工作,php包括脚本也在工作。

这是index.php:

include_once 'themes/default/views/layouts/main.php';

function showContent() {
//this is working fine
}

这是main.php一个普通的html5文档,其中包含css和jscript,并调用函数showContent():

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html" charset="UTF-8">

    <title>Tittle</title>

    <link rel="stylesheet" type="text/css" media="all" href="themes/default/css/cool_menu.css">

    <script type="text/JavaScript" src="js/sha512.js"></script>
    <script type="text/JavaScript" src="js/forms.js"></script>
</head>

<body>
    <header>
        <div>
            <p>Logo here</p>
        </div>
        <div>
             <p>Nav menu here</p>
             <ul>
                <li><a href="home">Home</a></li>
                <li><a href="login">login</a></li>
                <li><a href="register">register</a></li>
                <li><a href="about">About</a></li>
            </ul>
        </div>
    </header>

    <section>
        <article>
            <div>
                <p>Home and views content are called here</p>
                <?php
                $path = $_SERVER['DOCUMENT_ROOT'];
                include_once($path . '/index.php');
                showContent();
                ?>
            </div>
        </article>
    </section>

    <footer>
        <p>copyright here</p>
    </footer>
</body>
</html>

最后一个视图页面:login.php(注册也无效)

<?php

include_once 'includes/functions.php';

sec_session_start();    // no error so functions.php is included

if (login_check($mysqli) == true) {
    $logged = 'in';
} else {
    $logged = 'out';
}
?>

<!DOCTYPE html>
<html>
    <header>
    </header>
    <section>
        <?php
        if (isset($_GET['error'])) {
            echo '<p class="error">Error Logging In!</p>';
        }
        ?>
        <form action="includes/process_login.php" method="post" name="login_form">
            Email: <input type="text" name="email" />
            Password: <input type="password"
                             name="password"
                             id="password"/>
            <input type="button"
                   value="Login"
                   onclick="formhash(this.form, this.form.password);" />
        </form>
        <p>If you don't have a login, please <a href="register">register</a></p>
        <p>If you are done, please <a href="logout">log out</a>.</p>
        <p>You are currently logged <?php echo $logged ?>.</p>
    </section>
</html>

按钮不起作用......所以它是一个jscript问题,对吧?但它只是在我实现动态包含&#34; localhost / login&#34; ...之前正常工作...使用普通链接,如&#34; localhost / views / site / login.php&#34;它工作正常,但那不是问题...

这些文件夹(themes,includes和js)位于root(htdocs)中。 CSS样式工作正常,也可以在&#34; includes / functions.php&#34;也正在工作,但jscripts不是....

所有视图页面都有css和js包含,但我只是将它们移动到main.php,因为这不是问题。

我真的不知道问题是什么......有什么帮助吗?

谢谢!

编辑:添加forms.js jscript:

function formhash(form, password) {
// Create a new element input, this will be our hashed password field. 
var p = document.createElement("input");

// Add the new element to our form. 
form.appendChild(p);
p.name = "p";
p.type = "hidden";
p.value = hex_sha512(password.value);

// Make sure the plaintext password doesn't get sent. 
password.value = "";

// Finally submit the form. 
form.submit();
}

function regformhash(form, uid, email, password, conf) {
 // Check each field has a value
if (uid.value == ''         || 
      email.value == ''     || 
      password.value == ''  || 
      conf.value == '') {

    alert('You must provide all the requested details. Please try again');
    return false;
}

// Check the username

re = /^\w+$+/b; 
if(!re.test(form.username.value)) { 
    alert("Username must contain only letters, numbers and underscores. Please try again"); 
    form.username.focus();
    return false; 
}

// Check that the password is sufficiently long (min 6 chars)
// The check is duplicated below, but this is included to give more
// specific guidance to the user
if (password.value.length < 6) {
    alert('Passwords must be at least 6 characters long.  Please try again');
    form.password.focus();
    return false;
}

// At least one number, one lowercase and one uppercase letter 
// At least six characters 

var re = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/; 
if (!re.test(password.value)) {
    alert('Passwords must contain at least one number, one lowercase and one uppercase letter.  Please try again');
    return false;
}

// Check password and confirmation are the same
if (password.value != conf.value) {
    alert('Your password and confirmation do not match. Please try again');
    form.password.focus();
    return false;
}

// Create a new element input, this will be our hashed password field. 
var p = document.createElement("input");

// Add the new element to our form. 
form.appendChild(p);
p.name = "p";
p.type = "hidden";
p.value = hex_sha512(password.value);

// Make sure the plaintext password doesn't get sent. 
password.value = "";
conf.value = "";

// Finally submit the form. 
form.submit();
return true;
}

//End of Script

0 个答案:

没有答案