Nette\Forms\Form::addProtection PHP Method

addProtection() public method

Cross-Site Request Forgery (CSRF) form protection.
public addProtection ( $message = NULL ) : CsrfProtection
return Nette\Forms\Controls\CsrfProtection
    public function addProtection($message = NULL)
    {
        $control = new Controls\CsrfProtection($message);
        $this->addComponent($control, self::PROTECTOR_ID, key($this->getComponents()));
        return $control;
    }

Usage Example

Example #1
0
 function createForm()
 {
     $form = new Form();
     $form->addProtection('Detected robot activity.');
     $c = $form->addContainer('frm');
     $deliveryConstraints = $this->getDeliveryConstraints();
     if ($deliveryConstraints) {
         $c->addRadiolist(self::OPTION_DELIVERY, self::OPTION_DELIVERY, array_combine($deliveryConstraints, $deliveryConstraints))->setRequired()->setDefaultValue($this->getDelivery());
     }
     $paymentConstraints = $this->getPaymentConstraints();
     if ($paymentConstraints) {
         $c->addRadiolist(self::OPTION_PAYMENT, self::OPTION_PAYMENT, array_combine($paymentConstraints, $paymentConstraints))->setRequired()->setDefaultValue($this->getPayment());
     }
     $c->addText('delivery_name', 'delivery_name')->setRequired();
     $c->addTextarea('delivery_address', 'delivery_address');
     $c->addText('payment_name', 'payment_name');
     $c->addTextarea('payment_address', 'payment_address');
     $c->addText('payment_ic', 'payment_ic');
     $c->addText('payment_dic', 'payment_dic');
     if (!empty($this->config['allow_note'])) {
         $c->addTextarea('note', 'note');
     }
     $c->setDefaults($this->getOptions());
     $c->addSubmit('send', 'Save order');
     if (isFormValid($form, 'submit-order')) {
         $vals = $c->values;
         if ($vals[self::OPTION_PAYMENT]) {
             $this->setPayment($vals[self::OPTION_PAYMENT]);
         }
         if ($vals[self::OPTION_DELIVERY]) {
             $this->setDelivery($vals[self::OPTION_DELIVERY]);
         }
         $this->setOptions((array) $vals + $this->getOptions());
         wp_redirect('?');
     }
     return $form;
 }
All Usage Examples Of Nette\Forms\Form::addProtection