为什么我的表单会话消息没有显示? (jQuery的?)

时间:2012-08-20 13:55:28

标签: php jquery

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

我一直试图追查他们的错误,但不知道。他们在其他页面上工作但不是这一页。

有人可以帮助我找到我做的noobie错误吗?

这里的每个请求是一些可能相关的代码:

时间表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>

Signup.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;
  }
}

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

  1. 我必须在保存方法中使用$ this-email
  2. 我需要将表单设为实际的帖子
  3. 会话消息未输出(?)因为它没有抓住帖子