PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/application/forms/Link.php

https://github.com/kevinroberts/linkblab
PHP | 97 lines | 58 code | 19 blank | 20 comment | 0 complexity | 67b4487241a1500c09c2346003e52e25 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. class Application_Form_Link extends Zend_Form
  3. {
  4. public function init()
  5. {
  6. $this->setMethod('post');
  7. $this->setName("linkSubmit");
  8. // Make custom validations
  9. //$myValidator1 = new Zend_Validate_Regex(array('pattern' => '/^[a-zA-Z0-9!$@=+\][&#_\-%^*<>()?":;\'.\s]{2,150}$/'));
  10. $myValidator1 = new Zend_Validate_StringLength();
  11. $myValidator1->setMin(2); $myValidator1->setMax(150);
  12. $myValidator1->setMessage('Link title was not valid: 2-150 Alpha-numeric values only');
  13. $myValidators[] = $myValidator1;
  14. $myValidator2 = new Zend_Validate_StringLength();
  15. $myValidator2->setMin(2); $myValidator2->setMax(20000);
  16. $myValidator2->setMessage('Your description was not valid: 2-20000 Alpha-numeric values only');
  17. $myValidators2[] = $myValidator2;
  18. $utils = new Application_Model_Utils();
  19. $myValidator3 = new Zend_Validate_Callback(array($utils, 'isValidUrl'));
  20. $myValidator3->setMessage('You must enter a valid URL for your link');
  21. $myValidators3[] = $myValidator3;
  22. $myValidator4 = new Zend_Validate_Db_RecordExists(
  23. array(
  24. 'table' => 'blabs',
  25. 'field' => 'title'
  26. ));
  27. $myValidator4->setMessage('The Blab you entered does not exist');
  28. $myValidators4[] = $myValidator4;
  29. $element = new Zend_Form_Element_Text('title', array('disableLoadDefaultDecorators' => false));
  30. $element->addDecorator('ViewHelper')
  31. ->setRequired(true)
  32. ->addValidators($myValidators);
  33. //->addErrorMessage('Please provide a name for your Link');
  34. $this->addElement($element);
  35. $element = new Zend_Form_Element_Text('link_url', array('disableLoadDefaultDecorators' => false));
  36. $element->addDecorator('ViewHelper')
  37. ->setRequired(false)
  38. ->addValidators($myValidators3);
  39. //->addErrorMessage('Please provide a name for your Link');
  40. $this->addElement($element);
  41. $element = new Zend_Form_Element_Textarea('description', array('disableLoadDefaultDecorators' => false));
  42. $element->addDecorator('ViewHelper')
  43. ->setRequired(false)
  44. ->setFilters(array('StringTrim'))
  45. ->addValidators($myValidators2);
  46. //->addErrorMessage('A Blab title is required.');
  47. $this->addElement($element);
  48. $element = new Zend_Form_Element_Text('blab', array('disableLoadDefaultDecorators' => false));
  49. $element->addDecorator('ViewHelper')
  50. ->setRequired(true)
  51. ->addValidators($myValidators4);
  52. //->addErrorMessage('Please provide a name for your Link');
  53. $this->addElement($element);
  54. $element = new Zend_Form_Element_Hidden('isSelf', array('disableLoadDefaultDecorators' => true));
  55. $element->setValue('0')
  56. ->addDecorator('ViewHelper');
  57. $this->addElement($element);
  58. /*
  59. * Form security
  60. */
  61. $element = new Zend_Form_Element_Hash('___h', array('disableLoadDefaultDecorators' => true));
  62. $element->setSalt('unique')
  63. ->addDecorator('ViewHelper')
  64. ->addErrorMessage('There was a problem processing your request. Please try again.');
  65. $this->addElement($element);
  66. /* $element = new Zend_Form_Element_Captcha('captcha', array(
  67. 'label' => "Enter the text below:",
  68. 'captcha' => array(
  69. 'captcha' => 'Image',
  70. 'wordLen' => 4,
  71. 'timeout' => 300,
  72. 'font' => 'Arial'
  73. ),
  74. ));
  75. //$element->addErrorMessage('Invalid security captcha code');
  76. $this->addElement($element);*/
  77. }
  78. }