$t->is(select_tag('name', $option_for_select), '<select name="name" id="name">' . $option_for_select . '</select>', 'select_tag() takes an HTML string of options as its second argument'); $t->is(select_tag('name', array('item1')), '<select name="name" id="name">' . $option_for_select . '</select>', 'select_tag() takes an array of options as its second argument'); // options $t->is(select_tag('name', $option_for_select, array('class' => 'foo')), '<select name="name" id="name" class="foo">' . $option_for_select . '</select>', 'select_tag() takes an array of attribute options as its third argument'); $t->is(select_tag('name', $option_for_select, array('multiple' => true)), '<select name="name[]" id="name" multiple="multiple">' . $option_for_select . '</select>', 'select_tag() takes a "multiple" boolean option'); $t->is(select_tag('name[]', $option_for_select, array('multiple' => true)), '<select name="name[]" id="name" multiple="multiple">' . $option_for_select . '</select>', 'select_tag() takes a "multiple" boolean option'); $t->is(select_tag('name', $option_for_select, array('multiple' => false)), '<select name="name" id="name">' . $option_for_select . '</select>', 'select_tag() takes a "multiple" boolean option'); $t->is(select_tag('name', $option_for_select, array('id' => 'bar')), '<select name="name" id="bar">' . $option_for_select . '</select>', 'select_tag() can take a "id" option'); // select_country_tag() $t->diag('select_country_tag()'); $t->like(select_country_tag('name'), '/' . preg_quote('<select name="name" id="name">') . '/', 'select_country_tag() takes a name as its first argument'); $t->cmp_ok(preg_match_all('/<option/', select_country_tag('name'), $matches), '>', 200, 'select_country_tag() takes a name as its first argument'); $t->like(select_country_tag('name', 'FR'), '/' . preg_quote('<option value="FR" selected="selected">') . '/', 'select_country_tag() takes an ISO code for the selected country as its second argument'); // options $t->like(select_country_tag('name', null, array('class' => 'foo')), '/' . preg_quote('<select name="name" id="name" class="foo">') . '/', 'select_country_tag() takes an array of options as its third argument'); $t->is(preg_match_all('/<option/', select_country_tag('name', null, array('countries' => array('FR', 'GB'))), $matches), 2, 'select_country_tag() takes a "countries" option'); // select_language_tag() $t->diag('select_language_tag()'); $t->like(select_language_tag('name'), '/' . preg_quote('<select name="name" id="name">') . '/', 'select_language_tag() takes a name as its first argument'); $t->cmp_ok(preg_match_all('/<option/', select_language_tag('name'), $matches), '>', 200, 'select_language_tag() takes a name as its first argument'); $t->like(select_language_tag('name', 'fr'), '/' . preg_quote('<option value="fr" selected="selected">') . '/', 'select_language_tag() takes an ISO code for the selected language as its second argument'); // option $t->like(select_language_tag('name', null, array('class' => 'foo')), '/' . preg_quote('<select name="name" id="name" class="foo">') . '/', 'select_language_tag() takes an array of options as its third argument'); $t->is(preg_match_all('/<option/', select_language_tag('name', null, array('languages' => array('fr', 'en'))), $matches), 2, 'select_language_tag() takes a "languages" option'); // input_tag() $t->diag('input_tag()'); $t->is(input_tag('name'), '<input type="text" name="name" id="name" value="" />', 'input_tag() takes a name as its first argument'); $t->is(input_tag('name', 'foo'), '<input type="text" name="name" id="name" value="foo" />', 'input_tag() takes a value as its second argument'); // options $t->is(input_tag('name', null, array('class' => 'foo')), '<input type="text" name="name" id="name" value="" class="foo" />', 'input_tag() takes an array of attribute options as its third argument'); $t->is(input_tag('name', null, array('type' => 'password')), '<input type="password" name="name" id="name" value="" />', 'input_tag() can override the "type" attribute');
public function printParam($mandatory, $lable, $param_name, $input_type, $original_extra_params = NULL, $extra_params_for_select = NULL, $should_echo = NULL) { if ($should_echo == NULL) { $should_echo = $this->m_should_echo; } $res = ""; if ($this->m_object_type === self::OBJECT_TYPE_MY_BASE_OBJECT) { $p = $this->m_current_object->getParamFromObject($param_name); } else { if ($this->m_object_type === self::OBJECT_TYPE_ORM_BASE_OBJECT) { $p = baseObjectUtils::getParamFromObject($this->m_current_object, $param_name); } } // use this so the style=font-size:8pt will always be appended to the original_extra_params $extra_params = array(); //["style"] = "font-size:8pt"; kArray::associativePush($extra_params, $original_extra_params); if (kString::isEmpty($this->m_current_prefix)) { $field_name = $param_name; } else { $field_name = $this->m_current_prefix . self::PREFIX_NAME_SEPARATOR . $param_name; } $error = form_error($param_name); if ($this->m_create_tr) { if ($error) { $res .= "<tr><td colspan=2>" . $error . "</td></tr>"; } if ($input_type == "hidden") { $res .= "<tr><td></td>"; } else { $res .= " <tr><td valign=top><label for=\"" . $field_name . "\">" . ($mandatory ? "*" : "") . $lable . ":</label></td>"; } $res .= "<td sytle='font-size:8pt'>"; } else { // do nothing - the format will be done externally } if ($input_type == "text") { $res .= input_tag($field_name, $p, $extra_params); } elseif ($input_type == "hidden") { $res .= input_hidden_tag($field_name, $p, $extra_params); } elseif ($input_type == "textarea") { $res .= textarea_tag($field_name, $p, $extra_params); } elseif ($input_type == "upload") { $res .= self::createUploadStructure($field_name, $p, NULL, $extra_params, NULL, $should_echo); /* echo tag('input', array_merge(array('name' => $field_name, 'value' => $p , 'id' => $field_name, 'READONLY' => '', 'oncomplete' => 'onComplete_'.str_replace('.', '_', $field_name).'()'), $extra_params)); echo tag('input', array_merge(array('type' => 'button', 'value' => 'MyBrowse...', 'onclick' => 'uploadBrowse(this)', 'uploadElement' => "$field_name"), $extra_params)); echo tag('input', array_merge(array('type' => 'button', 'value' => 'Clear', 'onclick' => 'javascript:{$(\''.$field_name.'\').value = \'\';}'), $extra_params)); if ( ! kString::isEmpty ( $p ) ) { echo "<img src='/images/file_exists.png' width='16' height='16'>"; } */ } elseif ($input_type == "file") { $res .= input_file_tag($field_name, $p, $extra_params); } elseif ($input_type == "date") { $extra_params["rich"] = "true"; $extra_params["style"] = "width:80"; kArray::associativePush($extra_params, $original_extra_params); // TODO - see how to format the date there and back from the DB format "dd/mm/yyyy" to " $converted_date = dateUtils::convertFromPhpDate($p); // always append the default "rich=true" to the extra_params //$extra_params[] = 'rich=true' ; $res .= input_date_tag($field_name, $converted_date, $extra_params); } elseif ($input_type == "select") { $more_extra_params = array("style" => "font-size:8pt"); kArray::associativePush($more_extra_params, $extra_params_for_select); $res .= select_tag($field_name, options_for_select($original_extra_params, $p), $more_extra_params); } elseif ($input_type == "radio") { // assume the $lable holda the value of the radio $res .= radiobutton_tag($field_name, $lable, $p == $lable); } elseif ($input_type == "radiogroup") { // assume the $extra_params hold a lable-value array foreach ($extra_params as $lable => $name) { $value = $extra_params[$lable]; $res .= $lable . " " . radiobutton_tag($field_name, $value, $p == $value); } } elseif ($input_type == "checkbox") { $res .= checkbox_tag($field_name, "true", $p == "true", $extra_params); } elseif ($input_type == "color") { die("color is no longer supported !"); // $res .= myColorPicker::getPickerHtml( $p , $field_name ); // TODO - pass on $extra_params ? } elseif ($input_type == "country") { $more_extra_params = array("style" => "font-size:8pt"); kArray::associativePush($more_extra_params, $extra_params_for_select); $res .= select_country_tag($field_name, $p, $more_extra_params); } elseif ($input_type == "language") { $more_extra_params = array("style" => "font-size:8pt"); kArray::associativePush($more_extra_params, $extra_params_for_select); $res .= select_language_tag($field_name, $p, $more_extra_params); } else { throw new Exception("Unknown input_type [" . $input_type . "]"); } if ($this->m_create_tr) { $res .= "</td></tr>\n"; } if ($should_echo) { echo $res; } else { return $res; } }
function object_select_country_tag($object, $method, $options = array(), $default_value = null) { $options = _parse_attributes($options); $value = _get_object_value($object, $method, $default_value); return select_country_tag(_convert_method_to_name($method, $options), $value, $options); }
function select_country($path, $options = array(), $html_options = array()) { $name = _get_complete_bind_path($path); $bindStatus =& new BindStatus(_get_bind_path($path)); $boundValue = $bindStatus->getDisplayValue(); return select_country_tag($name, $boundValue, $options, $html_options); }