Changeset 413


Ignore:
Timestamp:
Oct 2, 2012 1:57:05 PM (12 years ago)
Author:
anonymous
Message:

Added header and footer to docs/examples. Updated message printing methods to include before, after, and gotohash options. Minor other fixes.

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/module_maker/module.cli.php

    r412 r413  
    136136}
    137137
    138 // Ensure essential directories exist.
    139 if (!is_dir("$admin_dir")) {
    140     die(basename($_SERVER['argv'][0]) . " Error: admin_dir '$admin_dir' directory not found.\n");
    141 }
    142 if (!is_dir("$admin_tpl_dir")) {
    143     die(basename($_SERVER['argv'][0]) . " Error: admin_tpl_dir '$admin_tpl_dir' directory not found.\n");
    144 }
    145 if (!is_dir("$public_dir")) {
    146     die(basename($_SERVER['argv'][0]) . " Error: public_dir '$public_dir' directory not found.\n");
    147 }
    148 if (!is_dir("$public_tpl_dir")) {
    149     die(basename($_SERVER['argv'][0]) . " Error: public_tpl_dir '$public_tpl_dir' directory not found.\n");
     138if (!isset($_SERVER['argv'][4]) || 'var' != $_SERVER['argv'][4]) {
     139    // Ensure essential directories exist, except for 'var' op.
     140    if (!is_dir("$admin_dir")) {
     141        die(basename($_SERVER['argv'][0]) . " Error: admin_dir '$admin_dir' directory not found.\n");
     142    }
     143    if (!is_dir("$admin_tpl_dir")) {
     144        die(basename($_SERVER['argv'][0]) . " Error: admin_tpl_dir '$admin_tpl_dir' directory not found.\n");
     145    }
     146    if (!is_dir("$public_dir")) {
     147        die(basename($_SERVER['argv'][0]) . " Error: public_dir '$public_dir' directory not found.\n");
     148    }
     149    if (!is_dir("$public_tpl_dir")) {
     150        die(basename($_SERVER['argv'][0]) . " Error: public_tpl_dir '$public_tpl_dir' directory not found.\n");
     151    }   
    150152}
    151153
  • trunk/docs/examples/contact_form/contact.php

    r396 r413  
    5151if (!empty($_POST)) {
    5252    // Validate submitted data.
    53     $fv->notEmpty('name', sprintf(_("%s cannot be blank."), _("Name")));
    54     $fv->stringLength('name', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Name"), 0, 255));
    55    
    56     $fv->notEmpty('email', sprintf(_("%s cannot be blank."), _("Email")));
    57     $fv->stringLength('email', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Email"), 0, 255));
    58     $fv->validateEmail('email');
    59    
    60     $fv->notEmpty('message', sprintf(_("%s cannot be blank."), _("Message")));
    61     $fv->stringLength('message', 0, 32000, sprintf(_("%s must be %d-to-%d characters in length."), _("Message"), 0, 32000));
    62        
     53    validateInput();
    6354    if ($fv->anyErrors()) {
    6455        // Re-populate form values with the user data so they can make corrections.
     
    6859        $email = new Email(array(
    6960            'to' => $email_to,
    70             'from' => sprintf('%s <%s>', $frm['name'], $frm['email']),
     61            'from' => sprintf('%s <%s>', getFormData('name'), getFormData('email')),
    7162            'subject' => 'Contact form email',
    7263        ));
    7364        $email->setTemplate('contact.eml');
    7465        $email->replace(array(
    75             'name' => $frm['name'],
    76             'email' => $frm['email'],
    77             'message' => $frm['question'],
     66            'name' => getFormData('name'),
     67            'email' => getFormData('email'),
     68            'message' => getFormData('message'),
    7869        ));
    7970        // Send email!
     
    113104}
    114105
     106function validateInput()
     107{
     108    global $fv;
     109
     110    $fv->notEmpty('name', sprintf(_("%s cannot be blank."), _("Name")));
     111    $fv->stringLength('name', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Name"), 0, 255));
     112   
     113    $fv->notEmpty('email', sprintf(_("%s cannot be blank."), _("Email")));
     114    $fv->stringLength('email', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Email"), 0, 255));
     115    $fv->validateEmail('email');
     116   
     117    $fv->notEmpty('message', sprintf(_("%s cannot be blank."), _("Message")));
     118    $fv->stringLength('message', 0, 32000, sprintf(_("%s must be %d-to-%d characters in length."), _("Message"), 0, 32000));
     119}
     120
    115121?>
  • trunk/lib/App.inc.php

    r410 r413  
    492492     * Prints the HTML for displaying raised messages.
    493493     *
     494     * @param   string  $above    Additional message to print above error messages (e.g. "Oops!").
     495     * @param   string  $below    Additional message to print below error messages (e.g. "Please fix and resubmit").
     496     * @param   string  $print_gotohash_js  Print a line of javascript that scrolls the browser window down to view any error messages.
     497     * @param   string  $hash     The #hashtag to scroll to.
    494498     * @access  public
    495499     * @author  Quinn Comendant <quinn@strangecode.com>
    496500     * @since   15 Jul 2005 01:39:14
    497501     */
    498     function printRaisedMessages()
     502    function printRaisedMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg')
    499503    {
    500504        if (!$this->running) {
     
    506510        if (!empty($messages)) {
    507511            ?><div id="sc-msg" class="sc-msg"><?php
     512            if ('' != $above) {
     513                ?><div class="sc-above"><?php echo oTxt($above); ?></div><?php
     514            }
    508515            foreach ($messages as $m) {
    509516                if (error_reporting() > 0 && $this->getParam('display_errors') && isset($m['file']) && isset($m['line'])) {
     
    530537                }
    531538            }
     539            if ('' != $below) {
     540                ?><div class="sc-below"><?php echo oTxt($below); ?></div><?php
     541            }
    532542            ?></div><?php
     543            if ($print_gotohash_js) {
     544                ?>
     545                <script type="text/javascript">
     546                /* <![CDATA[ */
     547                window.location.hash = '#<?php echo urlencode($hash); ?>';
     548                /* ]]> */
     549                </script>
     550                <?php
     551            }
    533552        }
    534553        $this->clearRaisedMessages();
  • trunk/lib/FormValidator.inc.php

    r396 r413  
    176176     * @param   string  $above    Additional message to print above error messages (e.g. "Oops!").
    177177     * @param   string  $below    Additional message to print below error messages (e.g. "Please fix and resubmit").
     178     * @param   string  $print_gotohash_js  Print a line of javascript that scrolls the browser window down to view any error messages.
     179     * @param   string  $hash     The #hashtag to scroll to.
    178180     * @access  public
    179181     * @author  Quinn Comendant <quinn@strangecode.com>
    180182     * @since   15 Jul 2005 01:39:14
    181183     */
    182     function printErrorMessages($above='', $below='')
     184    function printErrorMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg-formvalidator')
    183185    {
    184186        $app =& App::getInstance();
     
    217219            }
    218220            ?></div><?php
     221            if ($print_gotohash_js) {
     222                ?>
     223                <script type="text/javascript">
     224                /* <![CDATA[ */
     225                window.location.hash = '#<?php echo urlencode($hash); ?>';
     226                /* ]]> */
     227                </script>
     228                <?php
     229            }
    219230        }
    220231    }
Note: See TracChangeset for help on using the changeset viewer.