/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/form/form_elements/FEText.inc
ViewVC logotype

Diff of /nfo/php/libs/com.newsblob.phphtmllib/form/form_elements/FEText.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by jonen, Sat Feb 22 21:07:48 2003 UTC revision 1.2 by jonen, Sat Sep 20 00:20:15 2003 UTC
# Line 65  class FEText extends FormElement { Line 65  class FEText extends FormElement {
65          if (($value = $this->get_value()) != NULL)          if (($value = $this->get_value()) != NULL)
66              $attributes["value"] = $value;              $attributes["value"] = $value;
67    
68          $tag = new INPUTtag($attributes);          return new INPUTtag($attributes);
           
   
         return $tag;  
69      }      }
70  }  }
71    
# Line 91  class FEName extends FEText { Line 88  class FEName extends FEText {
88       * for this Form Element.       * for this Form Element.
89       *       *
90       * It validates as is_name().       * It validates as is_name().
91         * @param FormValidation object.
92       */       */
93      function validate() {      function validate(&$_FormValidation) {
94          $v = new FormValidation;          if (!$_FormValidation->is_name($this->get_value())) {
95          if (!$v->is_name($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
96              return FALSE;              return FALSE;
97          }          }
98          return TRUE;          return TRUE;
# Line 122  class FEEmail extends FEText { Line 119  class FEEmail extends FEText {
119       * for this Form Element.       * for this Form Element.
120       *       *
121       * It validates as is_email().       * It validates as is_email().
122         * @param FormValidation object.
123       */       */
124      function validate() {      function validate($_FormValidation) {
125          $v = new FormValidation;          if (!$_FormValidation->is_email($this->get_value())) {
126          if (!$v->is_email($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
127              return FALSE;              return FALSE;
128          }          }
129          return TRUE;          return TRUE;
# Line 155  class FEEmailMany extends FEText { Line 152  class FEEmailMany extends FEText {
152       * for this Form Element.       * for this Form Element.
153       *       *
154       * It validates as is_manyemails().       * It validates as is_manyemails().
155         * @param FormValidation object.
156       */       */
157      function validate() {      function validate(&$_FormValidation) {
158          $v = new FormValidation;          if (!$_FormValidation->is_manyemails($this->get_value())) {
159          if (!$v->is_manyemails($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
160              return FALSE;              return FALSE;
161          }          }
162          return TRUE;          return TRUE;
# Line 186  class FEDomainName extends FEText { Line 183  class FEDomainName extends FEText {
183       * for this Form Element.       * for this Form Element.
184       *       *
185       * It validates as is_domainname().       * It validates as is_domainname().
186         * @param FormValidation object.
187       */       */
188      function validate() {      function validate(&$_FormValidation) {
189          $v = new FormValidation;          if (!$_FormValidation->is_domainname($this->get_value())) {
190          if (!$v->is_domainname($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
191              return FALSE;              return FALSE;
192          }          }
193          return TRUE;          return TRUE;
# Line 198  class FEDomainName extends FEText { Line 195  class FEDomainName extends FEText {
195  }  }
196    
197  /**  /**
198   * This is the Ip Address FormElement which builds a   * This is the DomainName FormElement which builds a
199   * text input field.   * text input field. It also includes a port #
200   * It validates as is_ip().   * It validates as is_domainname().
201   *   *
202   *   *
203   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@buildabetterweb.com>
# Line 210  class FEDomainName extends FEText { Line 207  class FEDomainName extends FEText {
207   *   *
208   * @copyright LGPL - See LICENCE   * @copyright LGPL - See LICENCE
209   */   */
210  class FEIPAddress extends FEText {  class FEHostNameWithPort extends FEText {
211    
212        /**
213         * flag to tell us to seperate the port
214         * value into it's own field
215         */
216        var $_seperate_port_flag = FALSE;
217    
218        /**
219         * The constructor
220         *
221         * @param label string - text label for the element
222         * @param bool required - is this a required element
223         * @param int required - element width in characters, pixels (px), percentage (%) or elements (em)
224         * @param int required - maximum number of chars allowed to type in
225         * @param bool optional - seperate the port value into it's own textarea field
226         */
227        function FEHostNameWithPort($label, $required = TRUE, $width = NULL, $maxlength = NULL,
228                                      $seperate_port=FALSE) {
229            $this->FEText($label, $required, $width, $maxlength);
230            $this->_seperate_port_flag = $seperate_port;
231        }
232    
233        /**
234         * This function builds and returns the
235         * form element object
236         *
237         * @return object
238         */
239        function get_element() {
240            $host_attributes = $this->_build_element_attributes();
241            $host_attributes["type"] = "text";
242    
243            $element_name = $this->get_element_name();                
244            $host_value = $this->get_value();
245    
246            if ($this->_seperate_port_flag) {
247                $host_attributes["name"] = $element_name."[0]";
248                if ($host_value != NULL && !is_array($host_value)) {
249                    $host_value = explode(":", $host_value );
250                    $host_attributes["value"] = $host_value[0];
251                } else if (is_array($host_value)) {
252                    $host_attributes["value"] = $host_value[0];
253                }
254    
255                $port_attributes = $host_attributes;
256                $port_attributes["name"] = $element_name."[1]";
257                $port_attributes["size"] = 10;
258                $port_attributes["maxlenght"] = 5;
259                if (@array_key_exists("0", $host_value)) {
260                    $port_attributes["value"] = $host_value[1];
261                }
262    
263                $port_label = html_span("formlabel", "Port");
264                if ($this->has_error("Port")) {
265                    $port_label->set_tag_attribute("style","color:red;");
266                }            
267    
268                return container( new INPUTtag($host_attributes),
269                                  $port_label,
270                                  new INPUTtag($port_attributes));
271            } else {
272                if ($host_value != NULL) {
273                    $host_attributes["value"] = $host_value;
274                }
275                return new INPUTtag($host_attributes);
276            }
277        }
278    
279      /**      /**
280       * This method validates the data       * This method validates the data
281       * for this Form Element.       * for this Form Element.
282       *       *
283       * It validates as is_ip().       * It validates as is_domainname().
284         * @param FormValidation object.
285       */       */
286      function validate() {      function validate(&$_FormValidation) {
287          $v = new FormValidation;          $value = $this->get_value();
288          if (!$v->is_ip($this->get_value())) {          if (!is_array($value)) {
289              $this->set_error_message( $v->get_error_message() );              $value = explode(":", $value);
             return FALSE;  
290          }          }
291          return TRUE;          
292            $valid = $this->_validate_hostname($_FormValidation, $value[0]);
293    
294            //now validate the port
295            if ($value[1] != NULL) {
296                if (!$_FormValidation->is_number($value[1])) {
297                    if ($this->_seperate_port_flag) {
298                        $this->set_error_message($_FormValidation->get_error_message(), "Port");
299                    } else {
300                        $this->set_error_message( $_FormValidation->get_error_message() );
301                    }
302                    $value = FALSE;
303                }
304    
305                //make sure the hostname isn't null
306                if ($value[0] == NULL) {
307                    //we have an error here because
308                    //they entered a port w/o a hostname
309                    $_FormValidation->_error("", "This field cannot be empty, if the Port is filled out");
310                    $this->set_error_message($_FormValidation->get_error_message());
311                }
312            }
313            return $valid;
314        }
315    
316    
317        /**
318         * this validates the hostname field only
319         *
320         * @return bool TRUE = valid
321         */
322        function _validate_hostname(&$_FormValidation, $value) {
323            $valid = TRUE;
324            //validate the hostname        
325            if ($value != NULL && !$_FormValidation->is_hostname($value)) {
326                $this->set_error_message( $_FormValidation->get_error_message() );
327                $valid = FALSE;
328            }
329    
330            return $valid;
331      }      }
332  }  }
333    
334  /**  /**
335   * This is the float FormElement which builds a   * This is the Ip Address FormElement which builds a
336   * text input field.   * text input field.
337   * It validates as is_float().   * It validates as is_ip().
338   *   *
339   *   *
340   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@buildabetterweb.com>
# Line 241  class FEIPAddress extends FEText { Line 344  class FEIPAddress extends FEText {
344   *   *
345   * @copyright LGPL - See LICENCE   * @copyright LGPL - See LICENCE
346   */   */
347  class FENumberFloat extends FEText {  class FEIPAddress extends FEText {
348    
349      /**      /**
350       * This method validates the data       * This method validates the data
351       * for this Form Element.       * for this Form Element.
352       *       *
353       * It validates as is_float().       * It validates as is_ip().
354         * @param FormValidation object.
355       */       */
356      function validate() {      function validate(&$_FormValidation) {
357          $v = new FormValidation;          if (!$_FormValidation->is_ip($this->get_value())) {
358          if (!$v->is_float($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
359              return FALSE;              return FALSE;
360          }          }
361          return TRUE;          return TRUE;
# Line 260  class FENumberFloat extends FEText { Line 363  class FENumberFloat extends FEText {
363  }  }
364    
365  /**  /**
366   * This is the Price FormElement which builds a   * This is the Ip Address FormElement which builds a
367   * text input field.   * text input field.
368   * It validates as is_price().   * It validates as is_ip().
369   *   *
370   *   *
371   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@buildabetterweb.com>
# Line 272  class FENumberFloat extends FEText { Line 375  class FENumberFloat extends FEText {
375   *   *
376   * @copyright LGPL - See LICENCE   * @copyright LGPL - See LICENCE
377   */   */
378  class FENumberPrice extends FEText {  class FEIPAddressWithPort extends FEHostNameWithPort {
379    
380      /**      /**
381       * This method validates the data       * this validates the hostname field only
382       * for this Form Element.       *
383       *       * @return bool TRUE = valid
      * It validates as is_price().  
384       */       */
385      function validate() {      function _validate_hostname(&$_FormValidation, $value) {
386          $v = new FormValidation;          $valid = TRUE;
387          if (!$v->is_price($this->get_value())) {          //validate the hostname        
388              $this->set_error_message( $v->get_error_message() );          if ($value != NULL && !$_FormValidation->is_ip($value)) {
389              return FALSE;              $this->set_error_message( $_FormValidation->get_error_message() );
390                $valid = FALSE;
391          }          }
392          return TRUE;          return $valid;
393      }      }
394  }  }
395    
396    
397    
398  /**  /**
399   * This is the URL FormElement which builds a   * This is the URL FormElement which builds a
400   * text input field.   * text input field.
# Line 310  class FEUrl extends FEText { Line 415  class FEUrl extends FEText {
415       * for this Form Element.       * for this Form Element.
416       *       *
417       * It validates as is_url().       * It validates as is_url().
418         * @param FormValidation object.
419       */       */
420      function validate() {      function validate(&$_FormValidation) {
421          $v = new FormValidation;          if (!$_FormValidation->is_url($this->get_value())) {
422          if (!$v->is_url($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
423              return FALSE;              return FALSE;
424          }          }
425          return TRUE;          return TRUE;
# Line 342  class FEUrlStrict extends FEText { Line 447  class FEUrlStrict extends FEText {
447       * for this Form Element.       * for this Form Element.
448       *       *
449       * It validates as is_strict_url().       * It validates as is_strict_url().
450         * @param FormValidation object.
451       */       */
452      function validate() {      function validate(&$_FormValidation) {
453          $v = new FormValidation;          if (!$_FormValidation->is_strict_url($this->get_value())) {
454          if (!$v->is_strict_url($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
455              return FALSE;              return FALSE;
456          }          }
457          return TRUE;          return TRUE;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed