Username:
Password:
    Forgot your password?
Member Login

Building a Shout Box in Sitellite

Notes

Chat Loading chat status
  • Please subscribe to chat.
  • Older messages can be viewed in the chat archive.

Subscribe  |  The Lounge  |  Share Lesson

Chapter 3: Creating Our Shout Box Form

Before we can even display our Shout Box, we'll need a way to create some entries. In the "forms" folder, create a sub-folder named "add". In that folder we'll be creating three files:

access.php
Contains the access permissions for our form
index.php
Contains the PHP code for our form
settings.php
Contains the form definition, from which the form will automatically be generated

First, the access.php file. This just tells Sitellite that we want the form to be public and visible by anyone.

sitellite_status = approved
sitellite_access = public
sitellite_action = on

Next, our index.php file. This class will generate the Shout Box message submission form, as well as handle the posting of the message submissions. The onSubmit() method inserts the message into the database, then forwards the user to the screen they originally came from, which will have refreshed to include their message.

<?php

class ShoutboxAddForm extends MailForm {
    function ShoutboxAddForm () {
        parent::MailForm (__FILE__);
    }
    function onSubmit ($vals) {
        db_execute (
            'insert into shoutbox
                (id, name, url, ip_address, posted_on, message)
            values
                (null, ?, ?, ?, now(), ?)',
            $vals['name'],
            $vals['url'],
            $_SERVER['REMOTE_ADDR'],
            $vals['message']
        );

        header ('Location: ' . $_SERVER['HTTP_REFERER']);
        exit;
    }
}

?>

Now, we need to define the form in our settings.php file:

[Form]

[name]

type = text
alt = Your Name

[url]

type = text
alt = URL

[message]

type = text
alt = Your Message

[submit_button]

type = submit
setValues = Submit

Our form should now be ready. To see it, you can call it from the browser address bar via:

http://www.example.com/index/shoutbox-add-form

Chapter 4: Displaying the Shout Box »