submit button to disable client (js) validation but not server side validation

3 years ago

mikeb
Member | 30
+
0
-

Hello
i'm using nette\forms as standalone. i have a ‘save a draft’ submit button on a form:

$form->addSubmit('Draft', 'Save draft')
    ->setValidationScope([]);

setValidationScope([]) suppresses both client side and server side validation. i want to suppress client side but i still want server side validation so i can save valid entries in the ‘draft’ and not the invalid data.

is there a way to do this?

thanks!

3 years ago

mikeb
Member | 30
+
0
-

to answer my own question, this works:
when i build the form server side i check it first:

if($form->isSubmitted()){
    if(isset($_POST['Draft'])){// draft submit
        $form->validate();
        //... do check and saves here

and then add the save draft button AFTER these checks and before rendering

$form->addSubmit('Draft', 'Save draft')->setValidationScope([]);

there's probably a better way but this works.

HTH