PHP code example of mvccore / ext-form

1. Go to this page and download the library: Download mvccore/ext-form library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mvccore / ext-form example snippets


$form = (new \MvcCore\Ext\Form($mvcCoreController))
	->SetId('newsletter')
	->SetAction(
		$mvcCoreController->Url('Contact:Submit')
	)
	->SetSuccessUrl(
		$mvcCoreController->Url('Contact:Submitted')
	)
	->SetErrorUrl(
		$mvcCoreController->Url('Contact:Default')
	);
$email = (new \MvcCore\Ext\Form\Email)
	->SetName('mail')
	->SetLabel('Your email:')
	->SetRequired();
$submit = (new \MvcCore\Ext\Form\SubmitButton)
	->SetName('submit')
	->SetValue('Send');
$form->AddFields($email, $submit);
$mvcCoreController->view->newsletterForm = $form;

<body>
	 echo $this->newsletterForm; 

// ... form initialization again into var: $form 

// process all configured validators by: $form->Submit();
list($result, $data, $errors) = $form->Submit();

// if data has been submitted successfuly, 
// store user email somewhere in database:
if ($result == \MvcCore\Ext\Form::RESULT_SUCCESS) {
	// store user email somewhere by any custom model class (User):
	(new User())->SetEmail($data['mail'])->Save();
	// clear form session space to not display filled 
	// data by current user to another users
	$form->ClearSession();
}

// redirect user to configured success 
// or error url (by internal $form->Result property):
$form->SubmittedRedirect();