Php library for forms

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP library for creating HTML forms fast and easily with PHP. Takes care of all recurring and annoying tasks.

License

MatiasNAmendola/PHP_Forms

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Читайте также:  Indexing columns pandas python

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

PHP library for creating HTML forms fast and easily with PHP. Takes care of all recurring and annoying tasks.

  • support for all important form elements:
    • text input
    • hidden input
    • checkbox input
    • radio input
    • textarea
    • select list
    • submit button
    ?php include 'PHP_Forms.php'; ?> link rel pl-s">stylesheet" type pl-s">text/css" media pl-s">all" href pl-s">PHP_Forms.css" /> script type pl-s">text/javascript" src pl-s">PHP_Forms.js">script>
     $form = new PHP_Forms('Please fill out all required fields (*)!', true); $form->setMethod(PHP_Forms::METHOD_POST); $section_name = $form->addSection('Your name:'); $section_name->addInputText('name', 'name', true, 'Enter your name . '); $section_name->addInputText('surname', 'surname', true, 'Enter your surname . '); $section_about = $form->addSection('About you:'); $field_gender = $section_about->addInputRadioGroup('gender', 'Your gender', false, 'female'); $field_gender->addOption('I am male', 'male'); $field_gender->addOption('I am female', 'female'); $field_age = $section_about->addSelect('age', 'Your age:', true); for ($y = 12; $y < 99; $y++) < $field_age->addOption('I am '.$y.' years old', $y); > $form->showAntiSpam($section_about); $section_about->addInputSubmit('Submit form', 'button_submit'); echo $form->getHTML(); ?>

    Preview

     if (PHP_Forms::hasResponse(PHP_Forms::METHOD_POST)) < if (PHP_Forms::Response_isValid()) < $name = PHP_Forms::Response_getString('name'); $surname = PHP_Forms::Response_getString('surname'); $gender = PHP_Forms::Response_getString('gender'); $age = PHP_Forms::Response_getInt('age'); echo '

    '.$name.' '.$surname.' ('.$gender.') is '.$age.' years old.

    '
    ; > else < echo '

    Something went wrong

    '
    ; echo '

    Please fill out all required fields (*) and enter the correct solution to the arithmetic problem!

    '
    ; > > ?>
     $mail = new PHP_Forms_Mail('sender@example.org', 'John Doe', 'Sample subject'); $mail->addRecipient('jane@example.org'); $mail->addRecipient('ben@example.org', true); $mail->addLine('Dear Jane'); $mail->addLine(''); $mail->addLine('This is my message to you.'); $mail->addLine(''); $mail->addLine('John'); $mail->send(); ?>
     Copyright 2013 delight.im Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

    About

    PHP library for creating HTML forms fast and easily with PHP. Takes care of all recurring and annoying tasks.

    Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    PHP library to create and validate html forms

    License

    oscarotero/form-manager

    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

    Name already in use

    A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

    Sign In Required

    Please sign in to use Codespaces.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    Build Status Scrutinizer Code Quality

    Note: this is the documentation of FormManager 6.x

    This package requires PHP>=7.1 and is available on Packagist:

    composer require form-manager/form-manager 

    FormManager is namespaced, but you only need to import a single class into your context:

    use FormManager\Factory as F;

    Use the imported factory to create all form elements:

    //Create an input type="text" element $name = F::text(); //Create the input with a label $name = F::text('Please, introduce your name'); //Or with extra attributes $name = F::text('Please, introduce your name', ['class' => 'name-field']); //Add or remove attributes $name->setAttribute('title', 'This is the name input'); $name->removeAttribute('class'); $name->setAttributes([ 'required', 'readonly', 'tabindex' => 2, 'maxlength' => 50 ]); //Set the value $name->setValue('MyName'); //Use magic properties to get/set/remove attributes $name->class = 'name-field'; $name->required = false; unset($name->readonly);

    List of all available inputs:

    All HTML5 field types are supported:

    • F::checkbox($label, $attributes)
    • F::color($label, $attributes)
    • F::date($label, $attributes)
    • F::datetimeLocal($label, $attributes)
    • F::email($label, $attributes)
    • F::file($label, $attributes)
    • F::hidden($value, $attributes)
    • F::month($label, $attributes)
    • F::number($label, $attributes)
    • F::password($label, $attributes)
    • F::radio($label, $attributes)
    • F::range($label, $attributes)
    • F::search($label, $attributes)
    • F::select($label, $options, $attributes)
    • F::submit($label, $attributes)
    • F::tel($label, $attributes)
    • F::text($label, $attributes)
    • F::textarea($label, $attributes)
    • F::time($label, $attributes)
    • F::url($label, $attributes)
    • F::week($label, $attributes)

    Note that all inputs accepts the same arguments except hidden and select .

    This library uses internally symfony/validation to perform basic html5 validations and error reporting. HTML5 validation attributes like required , maxlength , minlength , pattern , etc are supported, in addition to intrinsic validations assigned to each input like email, url, date, etc.

    $email = F::email(); $email->setValue('invalid-email'); //Validate the value if ($email->isValid()) < return true; > //Get errors $error = $email->getError(); //Print the first error message echo $error; //Iterate through all messages foreach ($error as $err) < echo $err->getMessage(); > //You can also customize/translate the error messages $email->setErrorMessages([ 'email' => 'The email is not valid', 'required' => 'The email is required', 'maxlength' => 'The email is too long, it must have > characters or less', ]); //And add more symfony validators $ip = F::text(); $ip->addConstraint(new Constraints\Ip());
    $name = F::text('What is your name?', ['name' => 'name']); echo $name;
    label for pl-s">id-input-1">What is your name?label> input id pl-s">id-input-1" type pl-s">text" name pl-s">name">

    Set a custom template using > and > placeholders:

    $name->setTemplate('> 
    >
    '
    ); echo $name;
    label for pl-s">id-input-1">What is your name?label> div class pl-s">input-content">input id pl-s">id-input-1" type pl-s">text" name pl-s">name">div>

    If you want to wrap the previous template in a custom html, use the > placeholder:

    $name->setTemplate('
    >
    '
    ); echo $name;
    fieldset>label for pl-s">id-input-1">What is your name?label> div class pl-s">input-content">input id pl-s">id-input-1" type pl-s">text" name pl-s">name">div>fieldset>

    Group the fields to follow a specific data structure:

    Groups allow to place a set of inputs under an specific name:

    $group = F::group([ 'name' => F::text('Username'), 'email' => F::email('Email'), 'password' => F::password('Password'), ]); $group->setValue([ 'name' => 'oscar', 'email' => 'oom@oscarotero.com', 'password' => 'supersecret', ]);

    Special case for radios where all inputs share the same name with different values:

    $radios = F::radioGroup([ 'red' => 'Red', 'blue' => 'Blue', 'green' => 'Green', ]); $radios->setValue('blue');

    Special case to group several submit buttons under the same name but different values:

    $buttons = F::submitGroup([ 'save' => 'Save the row', 'duplicate' => 'Save as new row', ]); $buttons->setName('action');

    Is a collection of values using the same group:

    $groupCollection = F::groupCollection( f::group([ 'name' => F::text('Name'), 'genre' => F::radioGroup([ 'm' => 'Male', 'f' => 'Female', 'o' => 'Other', ]), ]) ]); $groupCollection->setValue([ [ 'name' => 'Oscar', 'genre' => 'm' ],[ 'name' => 'Laura', 'genre' => 'f' ], ])

    Multiple group collection

    Is a collection of values using various groups, using the field type to identify which group is used by each row:

    $multipleGroupCollection = F::multipleGroupCollection( 'text' => f::group([ 'type' => F::hidden(), 'title' => F::text('Title'), 'text' => F::textarea('Body'), ]), 'image' => f::group([ 'type' => F::hidden(), 'file' => F::file('Image file'), 'alt' => F::text('Alt text'), 'text' => F::textarea('Caption'), ]), 'link' => f::group([ 'type' => F::hidden(), 'text' => F::text('Link text'), 'href' => F::url('Url'), 'target' => F::select([ '_blank' => 'New window', '_self' => 'The same window', ]), ]), ]); $multipleGroupCollection->setValue([ [ 'type' => 'text', 'title' => 'Welcome to my page', 'text' => 'I hope you like it', ],[ 'type' => 'image', 'file' => 'avatar.jpg', 'alt' => 'Image of mine', 'text' => 'This is my photo', ],[ 'type' => 'link', 'text' => 'Go to my webpage', 'href' => 'https://oscarotero.com', 'target' => '_self', ], ]);

    Datalist are also allowed, just use the createDatalist() method:

    $input = F::search(); $datalist = $input->createDatalist([ 'female' => 'Female', 'male' => 'Male' ]); echo $input; echo $datalist;

    We need a form to put all this things together.

    $loginForm = F::form([ 'username' => F::text('User name'), 'password' => F::password('Password'), '' => F::submit('Login'), ]); $loginForm->setAttributes([ 'action' => 'login.php', 'method' => 'post', ]); //Load data from globals $_GET, $_POST, $_FILES $loginForm->loadFromGlobals(); //Load data passing the arrays $loginForm->loadFromArrays($_GET, $_POST, $_FILES); //Or load from PSR-7 server request $loginForm->loadFromServerRequest($serverRequest); //Get loaded data $data = $loginForm->getValue(); //Print the form echo $loginForm; //Access to specific inputs: echo $loginForm->getOpeningTag(); echo '

    Login:

    '
    ; echo $loginForm['username']; echo '
    '
    ; echo $loginForm['password']; echo '
    '
    ; echo $loginForm['']; echo $loginForm->getClosingTag(); //Iterate with all inputs echo $loginForm->getOpeningTag(); echo '

    Login:

    '
    ; foreach ($loginForm as $input) < echo " $input> "; > echo $loginForm->getClosingTag();

    About

    PHP library to create and validate html forms

    Источник

Оцените статью