PHP code example of wscore / ask

1. Go to this page and download the library: Download wscore/ask 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/ */

    

wscore / ask example snippets


function buildAskForms() {
    $ask = new \WScore\Ask\AskModel();

    $ask->addText('name', 'Your Name')
        ->setPlaceholder('Mr. Test Taro');
}

$ask = buildAskForms();
$forms = $ask->buildForm();

$forms->setFormClass('form-control');
$forms->setLabelClass('form-label');

<form action="..." method="post">
     $element = $forms->getElement('name'); 

$ask = buildAskForms();
$validator = $ask->buildValidator($_POST);
$results = $validator->getResults();

// show some message.
if ($validator->isValid()) {
    echo "<div class='alert alert-success'>Success!!!</div>";
} else {
    echo "<div class='alert alert-danger'>Error ???</div>";
}

<table class="table">
     $result = $validator->getResult('name') 

$ask->setValidator(function (Validation $validation) {
    $name = $valication->getResult('name');
    if (strlen($name) < 3) {
        $validation->setError('name', $name, 'must be longer than 2 characters.');
    }
});