1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: namespace Pry\Form\Element;
14:
15: 16: 17: 18: 19: 20: 21: 22:
23: class Radio extends Multi
24: {
25:
26: 27: 28: 29: 30: 31: 32:
33: public function __construct($nom, $form)
34: {
35: parent::__construct($nom, $form);
36: $this->attrs['type'] = 'radio';
37: }
38:
39: 40: 41: 42: 43:
44: public function __toString()
45: {
46: $css = $this->cssClass();
47: $label = '';
48: if (!empty($this->label))
49: {
50: $label = "\t" . '<span class="' . $this->cssLabel . '">' . $this->label . '</span>' . "\n";
51: if (!empty($this->info))
52: $label.="\t" . '<img src="' . $this->imgInfo . '" id="' . $this->attrs['name'] . '_tooltip" class="form_tooltip" title="' . $this->info . '" alt="" style="cursor:help;" />';
53: if ($this->labelNewLine)
54: $label.="\t" . '<br />' . "\n";
55: }
56:
57: $field = '';
58: $attributs = $this->attrsToString();
59:
60: $value = $this->form->getPostedvalue($this->attrs['name']);
61: if ($value == '')
62: $value = $this->value;
63:
64: foreach ($this->choix as $valhtml => $valAffichee) {
65: if ($value == $valhtml)
66: $checked = ' checked="checked"';
67: else
68: $checked = '';
69:
70: $field.="\t" . '<input ' . $css . ' value="' . htmlspecialchars($valhtml) . '" ' . $attributs . $checked . ' /> ' . $valAffichee . "\n";
71: if ($this->fieldNewLine)
72: $field.="\t" . '<br />' . "\n";
73: }
74: $error = '';
75: if (!is_null($this->errorMsg))
76: {
77: $error = '<span class="' . $this->errorClass . '">' . $this->errorMsg . '</span><br />';
78: }
79: return $label . $field . $error;
80: }
81:
82: }
83:
84: ?>