imran/form 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

imran/form

最新稳定版本:1.0.0

Composer 安装命令:

composer require imran/form

包简介

A simple and consistent way to generate various types of HTML form fields.

README 文档

README

The Form class is a utility class that provides a simple and consistent way to generate various types of HTML form fields.

Installation

You can Download the class file and include it in your project.

or you can install by using composer, this is recommended way.

composer require imran/form

Usage

Opening and closing a form

To create an opening form tag with attributes, use the open() method:

echo Form::open(['action' => '/submit', 'method' => 'post']);

To create a closing form tag, use the close() method:

echo Form::close();

Input fields

To create an input field of any type, use the input() method:

echo Form::input('text', 'first_name', 'John');
echo Form::input('date', 'birthday', '1990-01-01');

To create a textarea field, use the textarea() method:

echo Form::textarea('message', 'Hello, World!');

To create a checkbox field, use the checkbox() method:

echo Form::checkbox('agreement', 1, true);

To create a radio button, use the radio() method:

echo Form::radio('payment', 'credit', true);

To create a file input field, use the file() method:

echo Form::file('resume');

To create a password input field, use the password() method:

echo Form::password('password');

To create an email input field, use the email() method:

echo Form::email('email', 'example@example.com');

To create a label element, use the label() method:

echo Form::label('email', 'Email');

Registering Custom Types

You can register custom types by using the registerCustomType() method and passing in a name for the custom type and a callback function that will generate the HTML for that custom type.

Form::registerCustomType('custom_input', function($type, $name, $value, $attributes = []) {
    $attr_string = Form::attributesToString($attributes);
    return "<input type='$type' name='$name' value='$value' $attr_string>";
});

You can then use the registered custom type by using the custom() method and passing in the name of the custom type and an array of parameters to be passed to the callback function

echo Form::custom('custom_input', ['text', 'first_name', 'John']);

Running Tests

To run tests, use following command

.\vendor\bin\phpunit tests/FormTest.php

Conclusion

The Form class provides a simple and consistent way to generate various types of HTML form fields, making it easy to create forms in your PHP projects. You can also register your custom types to the class, giving you more flexibility and control over your forms. With the open() and close() methods, you can easily create the basic structure of a form, and with the various other methods, you can add different types of input fields, labels, and buttons to your form. The class also allows you to pass in attributes for each field, giving you more control over the appearance and behavior of your form fields. Overall, the Form class is a useful tool for creating and managing forms in your PHP projects.

Hi, I'm Imran Ali! 👋

🚀 About Me

Senior Full-Stack Developer specializing in front end and back-end development. Experienced with all stages of the development cycle for dynamic web projects. Innovative, creative and a proven team player, I possess a Tech Degree in Front End Development and have 7 years building developing and managing websites, applications and programs for various companies. I seek to secure the position of Senior Full Stack Developer where i can share my skills, expertise and experience with valuable clients.

🛠 Skills

PHP OOP, Laravel, Codeigniter Javascript, Node, React, Vue, Git, HTML, Rest Api, Typescript, Angular, SCSS, Docker, CI/CD Jenkins, Bootstrap, Responsive Design, ASP.NET Core

🔗 Follow on

linkedin twitter

License

MIT License GPLv3 License AGPL License

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Please adhere to this project's code of conduct.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固