Example #1
0
 /**
  * execute
  *
  * @param \Form\Form $form
  */
 public function update($form)
 {
     $config = \Tk\Config::getInstance();
     $data = $form->getObject();
     /* @var $field \Form\Field\Interface */
     foreach ($form->getFieldList() as $field) {
         if ($field->isRequired() && !$field->getValue() && $field->getName() != 'valid') {
             $field->addError('Please enter some valid data.');
         }
     }
     if ($form->hasErrors()) {
         return;
     }
     $message = '<table border="0" cellpadding="2" cellspacing="0" >';
     $message .= '<tr><th> Field </th><th> Value </th></tr>';
     $skip = array('__submitId', 'valid', 'send');
     /* @var $field \Form\Field\Interface */
     foreach ($form->getFieldList() as $field) {
         if (in_array($field->getName(), $skip)) {
             continue;
         }
         if ($field->getValue()) {
             $message .= '<tr><th class="label"> ' . $field->getLabel() . ': </th><td class="value"> ' . nl2br(htmlentities($field->getValue())) . ' </td></tr>';
         }
     }
     $message .= '</table>';
     $mail = new \Tk\Mail\Message();
     $mail->addTo($this->getConfig()->get('system.site.email'), $this->getConfig()->get('system.site.title'));
     $mail->setFrom($form->getFieldValue('email'), $form->getFieldValue('name'));
     $mail->setSubject('Contact Us Form Sent From ' . $this->getRequest()->getServer('HTTP_HOST'));
     $mail->setBody($mail->createHtmlTemplate($message));
     $mail->send();
     \Mod\Notice::addSuccess('Message Submited Successfully. Thank You!');
     $this->getUri()->redirect();
 }
 /**
  * Get error messages and init filters
  * 
  * @param \Form\Form $form
  */
 public function __construct(\Form\Form $form)
 {
     $this->error_msg = $form->errorForm();
     if ($this->error_msg) {
         \add_filter('save_post', array($this, 'getContentType'), 99);
     }
     \add_filter('post_updated_messages', array($this, 'addErrorMessage'));
 }
 public function test_set_values_form()
 {
     $input3 = $this->mockInputText('name3');
     $input2 = $this->mockInputText('name2');
     $input1 = $this->mockInputText('name1');
     $input3->expects($this->once())->method('setValue');
     $form = new Form();
     $form->addInput($input3);
     $aValues = array('name3' => 'value 3 du formulaire');
     $form->setValues($aValues);
     $form_html = $form->getDisplay();
 }
 /**
  * génère un formulaire prêt à l'emploi en fonction du tableau envoyé.
  *
  * Le tableau doit être de la forme :
  *
  *
  * array(
  *      array(
  *          'type' => 'Form\Input\Text\Text',
  *          'id' => 'test_id',
  *          'label' => 'label de mon champs',
  *          'desc' => 'description de mon champs'
  *      ),
  *      array(
  *          [...]
  *      )
  * )
  *
  */
 private function generateForm($post = null)
 {
     $form = new Form();
     $form->addInput(new Nonce());
     $this->formInstance = $form;
     foreach ($this->fields as $field) {
         // get value of this field if it exists for this post
         if (isset($post)) {
             $value = get_post_meta($post->ID, $field['id'], true);
         }
         $class_input = $field['type'];
         $field_id = $field['id'];
         $args = array('label' => $field['label'], 'desc' => $field['desc'], 'wysiwyg' => $field['wysiwyg'], 'content_type' => $this->content_type);
         if (isset($field['choices'])) {
             $args['choices'] = $field['choices'];
         }
         $input = new $class_input($field_id, $value, $field_id, $args);
         $this->formInstance->addInput($input);
     }
 }
 /**
  * URL: http://localhost:8080/?route=demo/four
  */
 public function four()
 {
     $form = new Form();
     $form->addField('firstname', 'WordField', array('blank' => false));
     $form->addField('lastname', 'WordField', array('blank' => false));
     $form->addField('telephone', 'NumericField');
     $values = null;
     if ($this->request->isMethodPost()) {
         $form->setValues($_POST);
         if ($form->isValid()) {
             $values = $form->getValues();
         }
     }
     $context = array('title' => 'four', 'form' => $form, 'values' => $values);
     $this->render('four.tpl', $context);
 }
Example #6
0
 /**
  * execute
  *
  * @param \Form\Form $form
  */
 public function update($form)
 {
     $fac = $this->getConfig()->getPluginFactory();
     $plugin = $fac->getPlugin($this->getNamespace());
     $arr = \Tk\ArrayObject::createArray($form->getFormValuesArray());
     if ($form->hasErrors()) {
         return;
     }
     $plugin->getDataArray()->importFormArray($arr);
     $plugin->getDataArray()->saveToDb();
     \Mod\Notice::addSuccess('Settings Saved.');
 }
Example #7
0
use Form\Form;
?>

<div class="well col-sm-6" style="margin-top: 40px; margin-left: 20px;">
	<?php 
echo Debug::getDataPost();
?>
</div>

<form class="form-horizontal" role="form" style="margin-top: 20px;" action="#" method="post">
	<div class="well col-sm-6" style="margin-left: 20px;">
	  <div class="form-group">
	    <label for="username" class="col-sm-2 control-label">Username</label>
	    <div class="col-sm-8">
	      <?php 
echo Form::input('username');
?>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="password" class="col-sm-2 control-label">Password</label>
	    <div class="col-sm-8">
	      <input type="password" class="form-control" id="password" name="password">
	    </div>
	  </div>
	  <div class="form-group">
	    <div class="col-sm-offset-2 col-sm-10">
	      <div class="checkbox">
	        <label>
	          <input type="checkbox"> Remember me
	        </label>
Example #8
0
 /**
  * execute
  *
  * @param \Form\Form $form
  */
 public function update($form)
 {
     /* @var $object \coa\Db\CoaSetup */
     $object = $form->getObject();
     /* @var $file \Form\Field\File */
     $file = $form->getField('pdfBgImage');
     if ($object instanceof \Tk\Db\Model) {
         $form->loadObject($object);
         $form->addFieldErrors($object->getValidator()->getErrors());
     }
     if ($form->hasErrors()) {
         if (!\Mod\Notice::hasMessages()) {
             \Mod\Notice::addError('The form contains errors.');
         }
         return;
     }
     $object->save();
     if ($file && $file->hasFile()) {
         $path = $object->getBasePath();
         \Tk\Path::rmdir($this->getConfig()->getDataPath() . $path);
         $file->moveUploadedFile($this->getConfig()->getDataPath() . $path . '/' . $file->getFileName());
         $object->pdfBgImage = $path . '/' . $file->getFileName();
         $object->save();
     }
     \Mod\Notice::addSuccess('Form submission successful');
 }
Example #9
0
 /** @expectedException \Form\FormException */
 public function testSubmitWrongData()
 {
     $form = new Form('product');
     $form->add(new Form('title'));
     $form->add(new Form('description'));
     $form->submit('foo');
 }
Example #10
0
 /**
  *
  * @return string
  */
 private function getFormAction() : string
 {
     $formTypeArray = explode('-', $this->form->getFormName());
     return @$formTypeArray[1] ?? $formTypeArray[0];
 }
Example #11
0
 /**
  * execute
  *
  * @param \Form\Form $form
  */
 public function update($form)
 {
     $object = new \LTI_Tool_Consumer($form->getFieldValue('key'), $this->getConfig()->getLtiDataConnector());
     // Load object
     $object->name = $form->getFieldValue('name');
     $object->secret = $form->getFieldValue('secret');
     $object->enabled = $form->getFieldValue('enabled');
     $object->protected = $form->getFieldValue('protected');
     $object->css_path = $form->getFieldValue('css_path');
     $object->updated = \Tk\Date::create()->getTimestamp();
     // validate object
     if (!$object->name) {
         $form->addFieldError('name', 'Please supply a valid consumer name');
     }
     if (!preg_match('/^[a-z0-9_-]{1,64}$/i', $object->getKey())) {
         $form->addFieldError('consumerKey', 'Invalid characters used in key field');
     }
     if (!preg_match('/^[a-z0-9]{1,64}$/i', $object->secret)) {
         $form->addFieldError('secret', 'Invalid characters used in secret field');
     }
     if ($form->hasErrors()) {
         if (!\Mod\Notice::hasMessages()) {
             \Mod\Notice::addError('The form contains errors.');
         }
         return;
     }
     if (!$this->getConfig()->getLtiDataConnector()->Tool_Consumer_save($object)) {
         if (!\Mod\Notice::hasMessages()) {
             \Mod\Notice::addError('Error saving consumer to DB.');
         }
         return;
     }
     //$this->getRedirectUrl()->set('key', $object->getKey())->redirect();
     $this->getRedirectUrl()->redirect();
 }
Example #12
0
 /**
  * doDefault
  */
 public function doDefault()
 {
     if (!$this->form->isSubmitted()) {
         $this->form->setFieldValue('system-maintenance-access-permission', explode(',', $this->getConfig()->get('system.maintenance.access.permission')));
     }
 }