liesauer/ql-plugin-simpleform

QueryList 插件 - SimpleForm

v4.0.1 2017-10-03 04:33 UTC

This package is auto-updated.

Last update: 2024-09-05 19:22:10 UTC


README

使表单提交更容易

安装

composer require liesauer/ql-plugin-simpleform

绑定

  • QueryList simpleForm ($formUrl, $formSelector = '', $formParams = [], $postParams = [], ...$args)
    • formUrl 获取表单的位置
    • formSelector 如果有多个表单元素则必须
    • formParams 用于获取表单,读取 QueryList::getQueryList::post,默认方法是 get
    • postParamsformParams 相同,但用于表单提交,默认方法是 post
    • args 未使用

用法

use liesauer\QLPlugin\SimpleForm;
use QL\QueryList;

require_once __DIR__ . '/vendor/autoload.php';

// cookie needed for this example
$cookie = new \GuzzleHttp\Cookie\CookieJar();

$ql = QueryList::getInstance();

// use this plugin
$ql->use(SimpleForm::class);

$username = $ql->simpleForm('https://github.com/login', '', [
    'options' => [
        'verify'  => false,
        'cookies' => $cookie,
    ],
], [
    'params'  => [
        'login'    => 'username',
        'password' => 'password',
    ],
    'options' => [
        'verify'  => false,
        'cookies' => $cookie,
    ],
])->find('.header-nav-current-user>.css-truncate-target')->text();

if (!empty($username)) {
    echo "welcome back, {$username}!\n";
} else {
    $error = $ql->find('.flash-error>.container')->text();
    echo "{$error}\n";
}