Beispiel #1
0
 public function onSubmit(Form $form)
 {
     $data = $form->getValues();
     // Předáme data do šablony
     $this->template->values = $data;
     $queueId = uniqid();
     \dibi::begin();
     $gallery_id = $this->gallery->insert(array("name" => $data["name"]));
     // Přesumene uploadované soubory
     foreach ($data["upload"] as $file) {
         // $file je instance HttpUploadedFile
         $newFilePath = FILESTORAGE_DIR . "/q{" . $queueId . "}__f{" . rand(10, 99) . "}__" . $file->getName();
         // V produkčním módu nepřesunujeme soubory...
         if (!Environment::isProduction()) {
             if ($file->move($newFilePath)) {
                 $this->flashMessage("Soubor " . $file->getName() . " byl úspěšně přesunut!");
             } else {
                 $this->flashMessage("Při přesouvání souboru " . $file->getName() . " nastala chyba! Pro více informací se podívejte do logů.");
             }
         }
         $this->files->insert($file);
         $this->gallery->addFile($gallery_id, $file_id);
         dump($file);
     }
     \dibi::commit();
 }
Beispiel #2
0
 public function saveEvent(Form $form)
 {
     $values = $form->getValues();
     if ($form['save']->isSubmittedBy()) {
         $categories = $values['categories'];
         unset($values['categories']);
         if ($form->onSuccess) {
             unset($values['agree']);
             $values['user_id'] = $this->user->loggedIn ? $this->user->id : null;
             $values['subject_id'] = 1;
             // anonymní akce // anonymní subjekt
             $values['approved'] = 0;
             $values['visible'] = 1;
             $values['reviewed'] = 0;
             $pd = $this->context->createService('events')->insert($values);
             $id = $pd->id;
             $this->flashMessage('Akce uložena do zásobníku', 'success');
             \dibi::begin();
             foreach ($categories as $n) {
                 \dibi::query('INSERT INTO [event_x_category] SET [event_id]=%i', $id, ', [category_id]=%i', $n);
             }
             \dibi::commit();
         }
         $form->addError('Something bad happend.');
     }
     $this->redirect('upload-photos', array('event_id' => $id));
 }
 /**
  * @inheritDoc
  */
 public function getValues($asArray = false)
 {
     $values = parent::getValues(true);
     // Sanitize Redirect URIs
     $redirect_uris = preg_split("/[\t\r\n]+/", $values['redirect_uri']);
     $redirect_uris = array_filter($redirect_uris, function ($redirect_uri) {
         return !empty(trim($redirect_uri));
     });
     $values['redirect_uri'] = $redirect_uris;
     return $values;
 }
Beispiel #4
0
 public function savePassword(Form $form)
 {
     $values = $form->getValues();
     try {
         $this->item->update(array('password' => hash("sha512", $values->prvniheslo . str_repeat('mooow', 10)), 'generated_password' => 0));
         $this->flashMessage('Password saved', 'success');
         $this->redirect('User:'******'error');
     }
 }
Beispiel #5
0
 public function savePassword(Form $form)
 {
     $values = $form->getValues();
     try {
         $users = $this->context->createServiceUsers();
         $users->get($this->user->id)->update(array('password' => $users->calculateHash($values['prvniheslo']), 'generated_password' => 0));
         $this->flashMessage('Password saved', 'success');
         $this->redirect('User:'******'error');
     }
 }
 public function createComponentArticleForm()
 {
     $form = new Nette\Forms\Form();
     $form->addText('title', 'Název')->setRequired('Název je povinný')->addRule(Form::MAX_LENGTH, 'Délka je maximálně 60 znaků', 60);
     $form->addTextArea('content', 'Obsah')->setRequired();
     $form->addButton('send', 'Přidat');
     $form->onSuccess[] = array($form, function ($form) {
         $values = $form->getValues();
         //doSomething($values->title);
     });
     return $form;
 }
 public function aktualityFormSuccess(Nette\Forms\Form $form)
 {
     $values = $form->getValues();
     $aktualitaId = $this->getParameter('id');
     if ($aktualitaId) {
         //Debugger::fireLog('editace');
         $this->aktualityModel->updateAktuality($aktualitaId, $values);
         $this->flashMessage("aktualita " . $values['name'] . " byla upravena");
         $this->redirect('Aktuality:prehledAktualit');
     } else {
         $this->aktualityModel->newAktualita($values);
         $this->flashMessage("Aktualita vložena");
         $this->redirect('Aktuality:prehledAktualit');
     }
 }
 public function rezervaceFormSuccess(Nette\Forms\Form $form)
 {
     $values = $form->getValues();
     $rezervaceId = $this->getParameter('id');
     if ($rezervaceId) {
         //Debugger::fireLog('editace');
         $this->rezervaceModel->updateRezervace($rezervaceId, $values);
         $this->flashMessage("Rezervace " . $values['name'] . " upravena");
         $this->redirect('Ubytovani:prehledRezervace');
     } else {
         //Debugger::fireLog('nova rezervace');
         $this->rezervaceModel->newRezervace($values);
         $this->flashMessage("Rezervace vložena");
         $this->redirect('Ubytovani:prehledRezervace');
     }
 }
Beispiel #9
0
 private function pageSaving(\Nette\Forms\Form $form, $isDraft)
 {
     if (!$this->authorizator->isAllowed($this->user, 'page', 'create') or !$this->authorizator->isAllowed($this->user, 'page', 'edit')) {
         $this->flashMessage('authorization.noPermission', FlashMessage::WARNING);
         return;
     }
     $values = $form->getValues(true);
     $values['saveAsDraft'] = (bool) $isDraft;
     $values['author'] = $this->user;
     $tags = $form->getHttpData(Form::DATA_TEXT, 'tags[]');
     $values['tags'] = $tags;
     try {
         $page = $this->pageFacade->save($values, $this->page);
         $this->flashMessage('pageEditForm.messages.success' . ($values['saveAsDraft'] ? 'Draft' : 'Publish'), FlashMessage::SUCCESS);
         $this->onSuccessPageSaving($this, $page);
     } catch (PagePublicationTimeMissingException $ptm) {
         $form->addError($this->translator->translate('pageEditForm.messages.missingPublicationTime'));
         return;
     } catch (PagePublicationTimeException $pt) {
         $form->addError($this->translator->translate('pageEditForm.messages.publishedPageInvalidPublicationTime'));
         return;
     } catch (PageIntroHtmlLengthException $pi) {
         $form->addError($this->translator->translate('pageEditForm.messages.pageIntroHtmlLength'));
         return;
     } catch (PageTitleAlreadyExistsException $at) {
         $form->addError($this->translator->translate('pageEditForm.messages.titleExists'));
         return;
     } catch (UrlAlreadyExistsException $ur) {
         $form['url']->setValue(Strings::webalize($values['title'], '/'));
         $form->addError($this->translator->translate('pageEditForm.messages.urlExists'));
         return;
     } catch (DBALException $e) {
         $form->addError($this->translator->translate('pageEditForm.messages.savingError'));
         return;
     }
 }
 /**
  * @param Form $form
  */
 public function quickSearchFormSucceeded(Form $form)
 {
     $v = $form->getValues();
     if (Strings::length($v->q) >= 3) {
         $this->fulltextQuery = $v->q;
     }
     if ($this->isAjax()) {
         $this->redrawControl('datalist');
     }
 }
Beispiel #11
0
$form->addHidden('b7', '[B7]');
$form->addText('stanoviste', 'Číslo stanoviště:')->setOption('description', 'Zadejte číslo stanoviště od 1 do 999')->setRequired('Zadejte číslo od 1 do 999')->addRule(Form::INTEGER, 'Stanoviště musí být číslo')->addRule(Form::RANGE, 'Číslo musí být od 1 do 99', array(1, 999))->setType('number');
$form->addHidden('cards');
$form->addHidden('ftp', '[FTP]');
$form->addHidden('server');
$form->addHidden('user');
$form->addHidden('password');
$form->addHidden('dstdir');
$form->addHidden('db', '[DB]');
$form->addHidden('script');
$form->addHidden('dbserver');
$form->addHidden('dbport');
$form->addHidden('dbuser');
$form->addHidden('dbpassword');
$form->addHidden('dbname');
$form->addHidden('dbtablename');
$form->addSubmit('send', 'Uložit');
$form->setDefaults($ini_array);
echo $form;
// vykreslí formulář
if ($form->isSuccess()) {
    $values = $form->getValues(true);
    if ($IniFile->write_php_ini($values)) {
        echo "\t<script>\n\t\t\t\t\t\t\talert('Formulář byl uložen');\n\t\t\t\t\t\t\twindow.location.replace('index.php');\n\t\t\t\t\t\t</script>)";
    }
}
?>
		</div>
	</body>
</html>
Beispiel #12
0
<div class="page-header">
  <h1>
    <i class="fa fa-plus"></i> Add a new station log
  </h1>
</div>
<?php 
use Nette\Forms\Form;
use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
$form = new Form();
$form->setRenderer(new BootstrapRenderer());
$form->addProtection();
$form->addText('reporter', 'Nickname')->setAttribute('placeholder', 'anonymous')->setRequired();
date_default_timezone_set("UTC");
$form->addText('datetime', 'When')->setAttribute('placeholder', '2014-01-01 14:00')->setDefaultValue(date('Y-m-d H:i:s'))->setRequired();
$form->addText('station', 'Station designator')->setRequired()->setAttribute('placeholder', 'E11');
$form->addText('qrh', 'Frequency')->setRequired()->setAttribute('placeholder', '4625')->addRule(Form::FLOAT);
$form->addText('callnumber', 'Call # (leave empty if not captured)')->setAttribute('placeholder', '472 639 5 or 441/30');
$form->addText('callid', 'Call ID (leave empty if not captured)')->setAttribute('placeholder', '472 639 5 or 441/30');
$form->addText('gc', 'Group Count')->setAttribute('placeholder', '10');
$form->addTextArea('body', 'Message (leave empty if not captured)')->setAttribute('placeholder', '39715 12345');
$form->addSubmit('send', 'Add to our mighty database');
if ($form->isSuccess() && $form->isValid()) {
    //die();
    $f = $form->getValues();
    //dump($f);
    $arr = array('time' => $f['datetime'], 'station' => $f['station'], 'qrh' => $f['qrh'], 'call_number' => $f['callnumber'], 'call_id' => $f['callid'], 'gc' => $f['gc'], 'body' => $f['body'], 'reporter' => $f['reporter']);
    dibi::query('insert into logs_new', $arr);
    echo "Log has been added. Thank you.";
}
$form->render();
Beispiel #13
0
// group Your account
$form->addGroup('Your account');
$form->addPassword('password', 'Choose password')->addRule(Form::FILLED, 'Choose your password')->addRule(Form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3)->setOption('description', '(at least 3 characters)');
$form->addPassword('password2', 'Reenter password')->addConditionOn($form['password'], Form::VALID)->addRule(Form::FILLED, 'Reenter your password')->addRule(Form::EQUAL, 'Passwords do not match', $form['password']);
$form->addFile('avatar', 'Picture');
$form->addHidden('userid');
$form->addTextArea('note', 'Comment');
// group for buttons
$form->addGroup();
$form->addSubmit('submit', 'Send');
// Step 2: Check if form was submitted?
if ($form->isSubmitted()) {
    // Step 2c: Check if form is valid
    if ($form->isValid()) {
        echo '<h2>Form was submitted and successfully validated</h2>';
        $values = $form->getValues();
        Debug::dump($values);
        // this is the end, my friend :-)
        if (empty($disableExit)) {
            exit;
        }
    }
} else {
    // not submitted, define default values
    $defaults = array('name' => 'John Doe', 'userid' => 231, 'country' => 'CZ');
    $form->setDefaults($defaults);
}
// Step 3: Render form
?>
<!DOCTYPE html>
<html lang="en">
Beispiel #14
0
$countries = ['World' => ['bu' => 'Buranda', 'qu' => 'Qumran', 'st' => 'Saint Georges Island'], '?' => 'other'];
$form->addSelect('country', 'Country:', $countries)->setPrompt('Select your country')->addConditionOn($form['send'], $form::FILLED)->setRequired('Select your country');
// group Your account
$form->addGroup('Your account');
$form->addPassword('password', 'Choose password:'******'Choose your password')->addRule($form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);
$form->addPassword('password2', 'Reenter password:'******'Reenter your password')->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
$form->addUpload('avatar', 'Picture:')->setRequired(FALSE)->addRule($form::IMAGE, 'Uploaded file is not image');
$form->addHidden('userid');
$form->addTextArea('note', 'Comment:');
// group for buttons
$form->addGroup();
$form->addSubmit('submit', 'Send');
$form->setDefaults(['name' => 'John Doe', 'userid' => 231]);
if ($form->isSuccess()) {
    echo '<h2>Form was submitted and successfully validated</h2>';
    Dumper::dump($form->getValues(), [Dumper::COLLAPSE => FALSE]);
    exit;
}
?>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Nette Forms basic example</title>
<link rel="stylesheet" media="screen" href="assets/style.css" />
<script src="https://nette.github.io/resources/js/netteForms.js"></script>

<h1>Nette Forms basic example</h1>

<?php 
echo $form;
?>
use Nette\Diagnostics\Debugger;
use Nette\Forms\Form;
// Generate form
$f = new Form("upload-form");
$f->getElementPrototype()->id = "frm";
$f->setMethod("GET");
$f->addSelect("speed", "Speed", array(1 => "1byte/s", 50 => "50bytes/s", 512 => "512bytes/s", 1 * FDTools::KILOBYTE => "1kb/s", 5 * FDTools::KILOBYTE => "5kb/s", 20 * FDTools::KILOBYTE => "20kb/s", 32 * FDTools::KILOBYTE => "32kb/s", 50 * FDTools::KILOBYTE => "50kb/s", 64 * FDTools::KILOBYTE => "64kb/s", 100 * FDTools::KILOBYTE => "100kb/s", 128 * FDTools::KILOBYTE => "128kb/s", 200 * FDTools::KILOBYTE => "200kb/s", 256 * FDTools::KILOBYTE => "256kb/s", 300 * FDTools::KILOBYTE => "300kb/s", 512 * FDTools::KILOBYTE => "512kb/s", 1 * FDTools::MEGABYTE => "1mb/s", 2 * FDTools::MEGABYTE => "2mb/s", 5 * FDTools::MEGABYTE => "5mb/s", 10 * FDTools::MEGABYTE => "10mb/s", 0 => "Unlimited"));
$f->addText("filename", "Filename")->addRule(Form::FILLED, "You must fill name!");
$f->addSelect("size", "Size", array(1 => "1MB", 4 => "4MB", 8 => "8MB", 16 => "16MB", 32 => "32MB", 64 => "64MB", 128 => "128MB", 256 => "256MB", 512 => "512MB"));
$f->addSelect("log", "Log called events?", array(0 => "No", 1 => "Yes (may cause CPU load)"));
$f->addSubmit("download", "Download!");
$f->setDefaults(array("speed" => 50, "filename" => "Some horrible file name - ěščřžýáíé.bin", "size" => 8, "log" => 1));
if ($f->isSubmitted() and $f->isValid()) {
    Debugger::enable(Debugger::PRODUCTION);
    // Log errors to file!
    $val = $f->getValues();
    $location = dirname(__FILE__) . "/cache/test-" . $val["size"] . "MB.tmp";
    if (!file_exists($location)) {
        generateFile($location, $val["size"] * 1024);
    }
    /* Interface with getters and setters */
    $file = new FileDownload();
    $file->sourceFile = $location;
    $file->transferFileName = $val["filename"];
    $file->speedLimit = (int) $val["speed"];
    //$file->mimeType = $val["mimeType"];
    /* Functions defined in example_library.php */
    if ($val["log"] == 1) {
        $file->onBeforeDownloaderStarts[] = "onBeforeDownloaderStarts";
        $file->onBeforeOutputStarts[] = "onBeforeOutputStarts";
        $file->onStatusChange[] = "onStatusChange";
 * @license   GNU Lesser General Public License
 * @link      http://www.radekdostal.cz
 */
use Nette\Forms\Form;
use Tracy\Debugger;
require '../vendor/autoload.php';
Debugger::$strictMode = TRUE;
Debugger::enable();
RadekDostal\NetteComponents\ImageSelectBox::register();
$items = array('calendar' => array('Calendar', 'img/icon_calendar.gif'), 'shopping_cart' => array('Shopping Cart', 'img/icon_cart.gif'), 'cd' => array('CD', 'img/icon_cd.gif'), 'email' => array('E-mail', 'img/icon_email.gif'), 'faq' => array('FAQ', 'img/icon_faq.gif'), 'games' => array('Games', 'img/icon_games.gif'), 'music' => array('Music', 'img/icon_music.gif'), 'phone' => array('Phone', 'img/icon_phone.gif'), 'graph' => array('Graph', 'img/icon_sales.gif'), 'secured' => array('Secured', 'img/icon_secure.gif'), 'video' => array('Video', 'img/icon_video.gif'));
$form = new Form();
$form->addImageSelectBox('item', 'Item:', $items)->setPrompt('— select any item —')->setRequired();
$form->addSubmit('submit', 'Send');
if ($form->isSuccess()) {
    echo '<h2>Form was submitted and successfully validated</h2>';
    dump($form->getValues());
    exit;
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="UTF-8">
  <meta name="author" content="Radek Dostál">
  <title>RadekDostal\NetteComponents\ImageSelectBox with jQuery and jQuery msDropDown plugin example</title>
  <link rel="stylesheet" type="text/css" href="js/jquery/plugins/msdropdown/css/dd.css">
  <script type="text/javascript" src="//code.jquery.com/jquery-3.1.0.min.js"></script>
  <script type="text/javascript" src="js/jquery/plugins/msdropdown/js/jquery.dd.min.js"></script>
  <script type="text/javascript">
    <!-- <![CDATA[
    $(document).ready(function()
Beispiel #17
0
$second = $form->addContainer('second');
$second->addText('name', 'Your name:');
$second->addText('email', 'Email:');
$second->addText('street', 'Street:');
$second->addText('city', 'City:');

// group for button
$form->addGroup();

$form->addSubmit('submit', 'Send');


if ($form->isSuccess()) {
	echo '<h2>Form was submitted and successfully validated</h2>';
	Dumper::dump($form->getValues());
	exit;
}


?>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Nette Forms containers example</title>
<link rel="stylesheet" media="screen" href="assets/style.css" />

<h1>Nette Forms containers example</h1>

<?php echo $form ?>

<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer>
Beispiel #18
0
 /**
  * Do the magic
  */
 public function processActions()
 {
     // WP_List_Table export
     \SimpleSubscribe\TableSubscribes::process();
     // settings form
     if ($this->formSettings->isSubmitted() && $this->formSettings->isValid()) {
         $values = $this->formSettings->getValues(TRUE);
         // if there are cateogires selected, and ALL as well, uncheck remaining
         if (count(array_filter($values['cat'])) > 0 && $values['cat']['0'] == TRUE) {
             foreach ($values['cat'] as $key => $value) {
                 $values['cat'][$key] = FALSE;
                 $this->formSettings['cat'][$key]->value = FALSE;
             }
             $values['cat']['0'] = TRUE;
             $this->formSettings['cat']['0']->value = TRUE;
             // if there is other category selected, unselect ALL
         } elseif (count(array_filter($values['cat'])) > 1) {
             $values['cat']['0'] = FALSE;
             $this->formSettings['cat']['0']->value = FALSE;
             // if there's no category selected, select ALL
         } elseif (!in_array(TRUE, $values['cat'])) {
             $values['cat']['0'] = TRUE;
             $this->formSettings['cat']['0']->value = TRUE;
         }
         $this->settings->saveSettings($values);
         $this->addNotice('updated', 'Settings successfully saved.');
     } elseif ($this->formSettings->hasErrors()) {
         foreach ($this->formSettings->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // email template (saved in settings table tho)
     if ($this->formEmailTemplate->isSubmitted() && $this->formEmailTemplate->isValid()) {
         $this->settings->saveSettings($this->formEmailTemplate->getValues(TRUE));
         $this->addNotice('updated', 'Settings successfully saved.');
     } elseif ($this->formEmailTemplate->hasErrors()) {
         foreach ($this->formEmailTemplate->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // mass email
     if ($this->formEmail->isSubmitted() && $this->formEmail->isValid()) {
         try {
             $this->email->sendMassEmail($this->formEmail->getValues(TRUE));
             $this->addNotice('updated', 'Email successfully sent.');
         } catch (EmailException $e) {
             $this->addNotice('error', $e->getMessage());
         }
     } elseif ($this->formEmail->hasErrors()) {
         foreach ($this->formEmail->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // subscriber form
     if ($this->formSubscriber->isSubmitted() && $this->formSubscriber->isValid()) {
         try {
             $this->subscribers->addThruAdmin($this->formSubscriber->getValues());
             $this->addNotice('updated', 'Subscriber successfully added.');
         } catch (RepositarySubscribersException $e) {
             $this->addNotice('error', $e->getMessage());
         }
     } elseif ($this->formSubscriber->hasErrors()) {
         foreach ($this->formSubscriber->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // wp subscriber form
     if ($this->formSubscriberWp->isSubmitted() && $this->formSubscriberWp->isValid()) {
         try {
             $users = $this->formSubscriberWp->getValues(TRUE);
             $this->subscribers->addWpRegistered($users['users']);
             $this->addNotice('updated', 'Subscriber(s) successfully added.');
         } catch (RepositarySubscribersException $e) {
             $this->addNotice('error', $e->getMessage());
         }
     } elseif ($this->formSubscriberWp->hasErrors()) {
         foreach ($this->formSubscriberWp->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // email preview form
     if ($this->formEmailPreview->isSubmitted() && $this->formEmailPreview->isValid()) {
         try {
             $this->email->sendEmailPreview($this->formEmailPreview->getValues(TRUE));
             $this->addNotice('updated', 'Email Preview successfully sent.');
         } catch (EmailException $e) {
             $this->addNotice('error', $e->getMessage());
         }
     } elseif ($this->formEmailPreview->hasErrors()) {
         foreach ($this->formEmailPreview->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
 }
 * @copyright Copyright (c) 2010 - 2016 Radek Dostál
 * @license   GNU Lesser General Public License
 * @link      http://www.radekdostal.cz
 */
use Nette\Forms\Form;
use Tracy\Debugger;
require '../vendor/autoload.php';
Debugger::$strictMode = TRUE;
Debugger::enable();
RadekDostal\NetteComponents\DateTimePicker\DateTimePicker::register();
$form = new Form();
$form->addDateTimePicker('datetime', 'Date and time:', 16)->setRequired()->setAttribute('size', 16);
$form->addSubmit('submit', 'Send');
if ($form->isSuccess() === TRUE) {
    echo '<h2>Form was submitted and successfully validated</h2>';
    Debugger::dump($form->getValues());
    exit;
}
/*else
{
  $form->setDefaults(array(
    'datetime' => new \DateTime()
  ));
}*/
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="UTF-8">
  <meta name="author" content="Radek Dostál">
  <title>RadekDostal\NetteComponents\DateTimePicker\DateTimePicker example</title>
Beispiel #20
0
 public function saveFile(Form $addForm)
 {
     $params = $this->getRequest()->getParams();
     $values = $addForm->getValues();
     $id = $params['id'];
     try {
         if ($this->gallery->addFile($id, $values['file_id'])) {
             $this->flashMessage('Image added into the gallery.', 'ok');
         } else {
             $this->flashMessage('Image is already in gallery.');
         }
     } catch (DibiException $e) {
         $this->flashMessage('Error' . $e, 'err');
     }
     $this->redirect('this');
 }