예제 #1
0
 function actionDefault()
 {
     // Mark the form as not valid
     $this->template->assign('formValid', false);
     // Create the form
     $form = new YDForm('emailForm');
     // Add the elements
     $form->addElement('text', 'email', 'Enter your email address:', array('style' => 'width: 300px;'));
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Apply a filter
     $form->addFilter('email', 'trim');
     // Add a rule
     $form->addRule('email', 'email', 'Please enter a valid email address');
     // Process the form
     if ($form->validate()) {
         // Mark the form as valid
         $this->template->assign('formValid', true);
         // Parse the template for the email
         $emlTpl = new YDTemplate();
         $emlTpl->assign('email', $form->getValue('email'));
         $body = $emlTpl->fetch('email_template', null);
         // Send the email
         $eml = new YDEmail();
         $eml->setFrom('*****@*****.**', YD_FW_NAME);
         $eml->addTo($form->getValue('email'), 'Yellow Duck');
         $eml->setSubject('Hello from Pieter & Fiona!');
         $eml->setHtmlBody($body);
         $eml->addAttachment('email.tpl');
         $eml->addHtmlImage('fsimage.jpg', 'image/jpeg');
         $result = $eml->send();
         // Add the result
         $this->template->assign('result', $result);
     }
     // Add the form to the template
     $this->template->assign('form_html', $form->toHtml());
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
 /**
  *        This function will return the element as HTML.
  *
  *        @returns        The form element as HTML text.
  */
 function toHtml()
 {
     // Create the list of attributes
     $attribs = array('id' => $this->_form . '_' . $this->_name);
     $attribs = array_merge($this->_attributes, $attribs);
     $template_record = new YDTemplate();
     // set form defaults
     if (isset($this->defaults)) {
         $this->form->setDefaults($this->defaults);
         $template_record->assign('defaults', $this->defaults);
     }
     // get record template and assign recordset
     $template_record->assign('recordset', $this->_value);
     $template_record->assign('columns', $this->columns);
     $template_record->assignForm('form', $this->form);
     // Get the HTML
     return $template_record->fetch(dirname(__FILE__) . '/YDFormElement_Grid.tpl');
 }