PHP code example of webclient / helper-form

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

    

webclient / helper-form example snippets




use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Webclient\Helper\Form\Wizard;

/**
 * @var RequestFactoryInterface $requestFactory
 * @var StreamFactoryInterface $streamFactory
 */
$wizard = new Wizard($requestFactory, $streamFactory);

$fh = fopen('/home/user42/.ssh/id_psa.pub', 'r+');

/** @var RequestInterface $request */
$request = $wizard
    ->createForm('http://localhost:8080/path?query=webclient#fragment', 'POST')
    ->addField('sign_up[login]', 'user42')
    ->addField('sign_up[password]', '$ecr3t')
    ->uploadFromString('about', 'hi!', 'about.txt', 'text/plain; charset=UTF-8')
    ->uploadFromFile('photo', '/home/user42/images/DCIM_4564.JPEG', 'image/jpeg', 'avatar.jpg')
    ->uploadFromResource('public_ssh_key', $fh, 'id_sra.pub', 'text/plain')
    ->createRequest()
;