PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Quickform - Select validation
Goto page Previous  1, 2
 
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTML
View previous topic :: View next topic  
Author Message
imchaz



Joined: 05 Jul 2007
Posts: 31

PostPosted: Tue Jul 10, 2007 8:46 pm    Post subject: Reply with quote

mark wrote:
Your example works here. I've used the array definitions that you've posted on "Mon Jul 09, 2007 20:56" and the rule definition from your last post. I'm then forced to select else than "Select State" before I can submit the form.

=> Check whether you have also changed something else. If you don't find the problem, then please show your complete code or at least the important parts of it.


mark, you are correct. The example I provided previously does work. But I thought my actual example in my code was similar so I adapted for my question. I guess I shouldnt assume shoudl I? Embarassed

Here is how I actually created my 2 arrays.

Code:
   $this->state= array(''=>'SELECT STATE');
   $this->company= array();

   $sql = "SELECT
            state.state_id AS state_id,
            state.state_name AS state_name, 
            ocn.id as ocn_id,
            ocn.name
         FROM
            state,
            ocn
         WHERE
            ocn.state_id = state.state_id
         ORDER BY
            state.state_id, ocn.name";
   
   $result = $this->db->query($sql);
      while ( $row = $result->fetch() ) {
        $this->state[$row['state_id']] = $row['state_name'];
        $this->company[$row['state_id']][$row['ocn_id']] = $row['name'];
      }
   }

$sel =& $form->addElement('hierselect', 'state_id', 'Select OCN Company:','class="signupData"','<br />');
$sel->setOptions(array($state,$company) );
$form->addGroupRule( 'state_id', array( 'state_id' => array( 0 => array( 'Selection Required!', 'nonzero', null, 'client' ) ) ) );   


I think my problem is when I create my $company array for its first key value pair.

How do I make first pair to look like this?
$company[0][0] = "";

right now I have it defined as
Code:

$this->company = array();


Thanks for being so patient with my questions.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1051

PostPosted: Tue Jul 10, 2007 8:48 pm    Post subject: Reply with quote

You're using both $this->company and $company, which have different meaning in PHP. If you do everything in one function, you can just use $company. If you build the array in one function and create the hierselect element in another function, you need the property syntax ($this->company). Same for $state, of course.
Back to top
View user's profile Send private message
imchaz



Joined: 05 Jul 2007
Posts: 31

PostPosted: Tue Jul 10, 2007 9:05 pm    Post subject: Reply with quote

mark wrote:
You're using both $this->company and $company, which have different meaning in PHP. If you do everything in one function, you can just use $company. If you build the array in one function and create the hierselect element in another function, you need the property syntax ($this->company). Same of $state, of course.


Mark you are correct, I hit submit before I can clean up my previous posting.

My revised code again...
Coming from a class
Code:

function get_state_company {
   $this->state= array(''=>'SELECT STATE');
   $this->company= array();

   $sql = "SELECT
            state.state_id AS state_id,
            state.state_name AS state_name,
            ocn.id as ocn_id,
            ocn.name
         FROM
            state,
            ocn
         WHERE
            ocn.state_id = state.state_id
         ORDER BY
            state.state_id, ocn.name";
   
   $result = $this->db->query($sql);
      while ( $row = $result->fetch() ) {
        $this->state[$row['state_id']] = $row['state_name'];
        $this->company[$row['state_id']][$row['ocn_id']] = $row['name'];
      }
   }
}

function get_state_array() {
return $this->state;
}
function get_company_array() {
return $this->company;
}

example.php page:
Code:

// Instantiate the User class
$user=& new User($db);

$user->get_state_company();

$sel =& $form->addElement('hierselect', 'state_id', 'Select OCN Company:','class="signupData"','<br />');
$sel->setOptions(array($user->get_state_array(),$user->get_company_array() ) );
$form->addGroupRule( 'state_id', array( 'state_id' => array( 0 => array( 'Selection Required!', 'nonzero', null, 'client' ) ) ) );   
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1051

PostPosted: Tue Jul 10, 2007 9:15 pm    Post subject: Reply with quote

The following *could* work:

Code:

   $this->state= array(0 =>'SELECT STATE');
   $this->company= array(0 => '');


Or maybe this one:

Code:

   $this->state= array(0 =>'SELECT STATE');
   $this->company= array(0 => array(0 => ''));


I'm too lazy to think about which one is the right one. Wink
Back to top
View user's profile Send private message
imchaz



Joined: 05 Jul 2007
Posts: 31

PostPosted: Tue Jul 10, 2007 9:33 pm    Post subject: Reply with quote

Mark,
Thanks...both versions do work. Very Happy
Now, I can move on to future problems. Wink

Once again, I appreciate your quick responses. Alex too.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTML All times are GMT + 2 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software