0

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

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

有人可以帮我找出我犯的新手错误吗?

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

调度-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;
  }
}
4

2 回答 2

0

您不需要将 session_start() 添加到您的 php 文件中吗?尝试这样做,让我知道这是否有帮助。

于 2012-08-20T14:01:47.483 回答
0
  1. 我不得不在保存方法中使用 $this-email
  2. 我需要使表格成为实际的帖子表格
  3. 会话消息没有被输出(?),因为它没有抓住帖子变量
于 2012-09-04T04:59:34.927 回答