 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
imchaz
Joined: 05 Jul 2007 Posts: 31
|
Posted: Tue Jul 10, 2007 8:46 pm Post subject: |
|
|
| 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?
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1051
|
Posted: Tue Jul 10, 2007 8:48 pm Post subject: |
|
|
| 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 |
|
 |
imchaz
Joined: 05 Jul 2007 Posts: 31
|
Posted: Tue Jul 10, 2007 9:05 pm Post subject: |
|
|
| 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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1051
|
Posted: Tue Jul 10, 2007 9:15 pm Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
imchaz
Joined: 05 Jul 2007 Posts: 31
|
Posted: Tue Jul 10, 2007 9:33 pm Post subject: |
|
|
Mark,
Thanks...both versions do work.
Now, I can move on to future problems.
Once again, I appreciate your quick responses. Alex too. |
|
| Back to top |
|
 |
|
|
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
|
|