Jump to content


Photo

Can't see global variable in member function?


  • Please log in to reply
3 replies to this topic

#1 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 10 June 2006 - 08:34 PM

I reinstalled XAMPP today on my development machine, set everything up and it works. Except now I have errors about a global error being undefined.

I have a global array defined in validate.php
  $g_pregs['raidname'] = '/^[a-zA-Z0-9 ()]{1,32}$/';
  $g_pregs['charname'] = '/^[A-Z][a-z]{1,28}$/';
  $g_pregs['username'] = '/^[a-zA-Z0-9]{2,30}$/';
  $g_pregs['password'] = '/^[a-zA-Z0-9]{3,20}$/';
  $g_pregs['email'] = '/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+(\.[a-zA-Z]{2,4})+$/';
  $g_pregs['alpha'] = '/^[a-zA-Z]+$/';
  $g_pregs['digit'] = '/^[0-9]+$/';

Then I have a CForm.php that defines a CForm object
  require_once('validate.php');
  
  class CForm{
    // ValidateForm
    // Do basic form validating, ensuring that all required fields in
    // $m_required are present, also ensure that all fields in $m_formats
    // match the required format
    // RETURN: true on success, false otherwise
    function ValidateForm(){
      global $g_pregs;

      // Next we check for specific formatting of the fields
      if( is_array( $this->m_formats ) ){
        foreach($this->m_formats as $format){
          if( !preg_match($g_pregs[$format[1]], $_POST[$format[0]]) ){
            // the format is invalid, add error message
            $this->AddError($format[2]);
            $this->AddErrorIndicator($format[0]);
          }
        }
      }
      /* More function code */
     return $value;
    }
  }


The problem is now my $g_pregs is empty inside the CForm::ValidateForm method. I'm unsure why.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#2 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 11 June 2006 - 12:01 AM

/bump

Anyone? I can't develop my site and I have no idea why this is happening.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 11 June 2006 - 10:54 AM

included file needs php tags

<?php
$g_pregs['raidname'] = '/^[a-zA-Z0-9 ()]{1,32}$/';
  $g_pregs['charname'] = '/^[A-Z][a-z]{1,28}$/';
  $g_pregs['username'] = '/^[a-zA-Z0-9]{2,30}$/';
  $g_pregs['password'] = '/^[a-zA-Z0-9]{3,20}$/';
  $g_pregs['email'] = '/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+(\.[a-zA-Z]{2,4})+$/';
  $g_pregs['alpha'] = '/^[a-zA-Z]+$/';
  $g_pregs['digit'] = '/^[0-9]+$/';
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 11 June 2006 - 09:38 PM

It has them. This is a dev site that has always worked until I reinstalled XAMPP. I'm assuming a php setting was changed which is causing the problem. But I'm not sure what it is.

[!--quoteo(post=382459:date=Jun 11 2006, 03:54 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Jun 11 2006, 03:54 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
included file needs php tags

<?php
$g_pregs['raidname'] = '/^[a-zA-Z0-9 ()]{1,32}$/';
  $g_pregs['charname'] = '/^[A-Z][a-z]{1,28}$/';
  $g_pregs['username'] = '/^[a-zA-Z0-9]{2,30}$/';
  $g_pregs['password'] = '/^[a-zA-Z0-9]{3,20}$/';
  $g_pregs['email'] = '/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+(\.[a-zA-Z]{2,4})+$/';
  $g_pregs['alpha'] = '/^[a-zA-Z]+$/';
  $g_pregs['digit'] = '/^[0-9]+$/';
?>
[/quote]

PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users