为什么';我的表单会话消息没有显示吗?(Jquery?)


Why aren't my form session messages being shown? (Jquery?)

我在这里有一个页面:https://github.com/alexwaters/PWTKD-new-CMS/blob/master/taekwondo/schedule-dev.php没有显示我的会话消息:<?php echo output_message($message); ?>

我一直在试图找出他们到底出了什么问题,但不知道。他们在其他页面上工作,但在这一页上没有。

有人能帮我找出我犯的小错误吗?

根据请求,这里有一些可能相关的代码:

schedule-dev.php

<?php require_once("../includes/initialize.php"); ?>
<?php $schedules = Schedule::find_all();?>
<?php $messages = Messages::find_by_id(1);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.2.6.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#contactLink").click(function(){
            if ($("#contactForm").is(":hidden")){
                $("#contactForm").slideDown("slow");
            }else{
                $("#contactForm").slideUp("slow");
            }
        });
    });
    function closeForm(){
        $("#messageSent").show("slow");
        setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
    }
</script>

<?php 
if(isset($_POST['signupSubmit'])){
    $signup = new Signup();
    $signup->name = $_POST['name'];
    $signup->age = $_POST['email'];
    if($signup->save()) {
        $session->message("We will contact you with details.");
        redirect_to('schedule.php');
    } else {
        $message = join("test", $signup->errors);
    }
}
?>
<?php echo output_message($message); ?>
    <div id="contactFormContainer">
        <div id="contactLink"></div>
        <div id="contactForm">
            <fieldset>
                <label for="name">Name *</label>
                <input id="name" type="text" />
                <label for="email">Email address *</label>
                <input id="email" type="text" />
                <input id="sendMail" type="submit" name="signupSubmit" onclick="closeForm()" />
                <span id="messageSent"></span>
            </fieldset>     
        </div>
    </div>

注册.php

<?php
// If it's going to need the database, then it's 
// probably smart to require it before we start.
require_once(LIB_PATH.DS.'database.php');
class Signup extends DatabaseObject {
    protected static $table_name="signup";
    protected static $db_fields=array('id', 'name','email');
    public $id;
    public $name;
    public $email;
    public $errors=array();
    public function save() {
        // A new record won't have an id yet.
        if(isset($this->id)) {
            // Really just to update the name
            $this->update();
            return true;
        } else {
            // Make sure there are no errors
            // Can't save if there are pre-existing errors
            if(!empty($this->errors)) { return false; }
            // Make sure the name is not too long for the DB
            if(strlen($this->name) >= 255) {
                $this->errors[] = "Name must be <= 255 characters long.";
                return false;
            }
            if(strlen($this->email) >= 255) {
                $this->errors[] = "Email must be <= 255 characters long.";
                return false;
            }
            if(empty($email)) {
                $this->errors[] = "Please enter an email address";
                return false;
            }
            //Finally add the item to the DB
            if($this->create()) {
                return true;
            } else {
                // 
                $this->errors[] = "Send failed, please contact us";
                return false;
            }
        }
    }

和其他一些通用类的东西

来自session.php的消息方法

public function message($msg="") {
  if(!empty($msg)) {
    // then this is "set message"
    // make sure you understand why $this->message=$msg wouldn't work
    $_SESSION['message'] = $msg;
  } else {
    // then this is "get message"
        return $this->message;
  }
}

您不需要将session_start()添加到php文件中吗?试着这样做,如果有帮助,请告诉我。

  1. 我不得不在保存方法中使用$this电子邮件
  2. 我需要把表格做成一个实际的邮寄表格
  3. 会话消息没有被输出(?),因为它没有获取post-var