Permalink
Browse files

Error is suppressed if the session is already started, and indefined …

…index error should no longer be thrown when accessing session vars.
  • Loading branch information...
chrisjaure committed Apr 11, 2009
1 parent 594db4d commit 62930fb14e86f184fb78d76d4cd8124af2fa3703
Showing with 14 additions and 8 deletions.
  1. +5 −0 source/inc/functions.php
  2. +6 −5 source/inc/templates/form.php
  3. +3 −3 source/index.php
View
@@ -21,4 +21,9 @@ function __($str) {
function _e($str) {
echo __($str);
}
+
+// get session variable if it exists
+function _s($key) {
+ if (isset($_SESSION[$key])) echo $_SESSION[$key];
+}
?>
@@ -7,18 +7,19 @@
<label for="name">
<?php _e('Name'); ?>: <span class="required">(<?php _e('required'); ?>)</span>
</label>
- <input id="name" name="name" type="text" value="<?php echo $_SESSION['form_name']; ?>"/>
+ <input id="name" name="name" type="text" value="<?php _s('form_name'); ?>"/>
<label for="website">
<?php _e('Website'); ?>:
</label>
- <input id="website" name="website" type="text" value="<?php echo $_SESSION['form_website']; ?>"/>
+ <input id="website" name="website" type="text" value="<?php _s('form_website'); ?>"/>
<label for="comment">
<?php _e('Comment'); ?>: <span class="required">(<?php _e('required'); ?>)</span>
</label>
- <textarea id="comment" rows="" cols="" name="comment"><?php echo $_SESSION['form_comment']; ?></textarea>
+ <textarea id="comment" rows="" cols="" name="comment"><?php echo _s('form_comment'); ?></textarea>
<label class="hidden" for="jbemail">
<?php _e('Do not fill out this field.'); ?>
</label>
- <input class="hidden" id="jbemail" name="jbemail" type="text" value=""/><input type="submit" class="button" value="<?php _e('Add it!'); ?>"/>
+ <input class="hidden" id="jbemail" name="jbemail" type="text" value=""/>
+ <input type="submit" class="button" value="<?php _e('Add it!'); ?>"/>
</fieldset>
-</form>
+</form>
View
@@ -8,7 +8,7 @@
// index.php
//-------------------------------------------------------------------------------------
-session_start(); // start the session so we can get any form values or errors set by non-ajax users
+@session_start(); // start the session so we can get any form values or errors set by non-ajax users
require_once('inc/includes.php');
includes(array('actions/loadcomments.php', 'actions/transformxml.php'));
@@ -44,9 +44,9 @@
&mdash; A Free AJAX Guestbook
</div>
</div>
- <div id="jb_message" class="<?php echo $_SESSION['message_type']; ?>">
+ <div id="jb_message" class="<?php _s('message_type'); ?>">
<p>
- <?php echo $_SESSION['message']; ?>
+ <?php _s('message'); ?>
</p>
</div>
<div id="content">

0 comments on commit 62930fb

Please sign in to comment.