X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plekit%2Fphp%2Fform.php;h=f12d53e98d7a089fdd4e21d1ea588d3a268dfd2e;hb=cc69977eaad2e905c9496db4f466640ad3d96b0f;hp=d4ee499931d82a2ee68312c0ac771a3003638a77;hpb=ba21c1dfba2403dd3aca6383e232fe2be2f32367;p=plewww.git diff --git a/plekit/php/form.php b/plekit/php/form.php index d4ee499..f12d53e 100644 --- a/plekit/php/form.php +++ b/plekit/php/form.php @@ -12,9 +12,11 @@ class PlekitForm { // mandatory var $url; var $values; // a hash var=>value - default is empty array - var $method; // default is POST + var $method; // default is POST, can be changed with options + var $onSubmit; // can be set with options + var $onReset; // can be set with options - function PlekitForm ($full_url, $values, $method="POST") { + function PlekitForm ($full_url, $values, $options=NULL) { // so we can use the various l_* functions: // we parse the url to extract var-values pairs, // and add them to the 'values' argument if any @@ -29,12 +31,17 @@ class PlekitForm { $this->values=$values; // make strict xhtml happy - $this->method=strtolower($method); + $this->method="post"; if ($options['method']) $this->method=strtolower($options['method']); + $this->onSubmit=NULL; if ($options['onSubmit']) $this->onSubmit=$options['onSubmit']; + $this->onReset=NULL; if ($options['onReset']) $this->onReset=$options['onReset']; } function start () { print $this->start_html(); } function start_html () { - $html="
"; + $html="onSubmit) $html .= " onSubmit='$this->onSubmit'"; + if ($this->onReset) $html .= " onReset='$this->onReset'"; + $html .= ">"; if ($this->values) foreach ($this->values as $key=>$value) $html .= $this->hidden_html($key,$value); @@ -128,40 +135,23 @@ class PlekitForm { // helper function to handle role-oriented selectors // because GetRoles does not correctly support filters, it's really painful to do this - static public function role_selectors($api,$role_ids=NULL,$current=NULL) { + static public function role_selectors($roles,$current_id=NULL) { function role_selector ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); } - function role_id ($role) { return $role['role_id']; } - - $all_roles=$api->GetRoles(); - if ( ! $role_ids) - $role_ids=array_map("role_id",$all_roles); - $selectors=array(); // preserve input order - foreach ($role_ids as $role_id) { - foreach ($all_roles as $all_role) { - if ($all_role['role_id'] == $role_id) { - $selector=role_selector($all_role); - if ($role_id == $current) + if ( ! $roles) { + drupal_set_message('WARNING: empty roles in role_selectors'); + } else { + foreach ($roles as $role) { + $selector=role_selector($role); + if ($role['role_id'] == $current_id) $selector['selected']=true; - $selectors []= $selector; - } + $selectors []= $selector; } } return $selectors; } - static public function role_selectors_excluding ($api,$exclude_role_ids=NULL,$current=NULL) { - if ( ! $exclude_role_ids ) $exclude_role_ids = array(); - $all_roles=$api->GetRoles(); - $role_ids = array(); - foreach ($all_roles as $role) { - if ( ! in_array ($role['role_id'],$exclude_role_ids)) { - $role_ids [] = $role['role_id']; - } - } - return PlekitForm::role_selectors($api,$role_ids,$current); - } } // a form with a single button