If you are using CodeIgniter, as
well as any other PHP framework, you may notice that building CRUD
forms is one of the most bother and routine tasks. Probably 80% of
general web applications uses CRUD
(create/read/update/delete).
In CodeIgniter, you can use any of the form generation libraries
.
One of my preferred libraries is Form Generation Library by Frank Michel
(see @macigniter’s thread here
). It allows you to create clean XHTML forms with CodeIgniter. See demo here
.
Using Form Generation Library
So, in order to use this library, you need to download it from here
(library files only
is enough if you don’t want the entire site structure).
Make sure to follow the installation steps, as shown here
. That means unzipping the package, configuring config/form.php and moving config/form.php
and libraries/form.php
to the right directories.
Let’s assume we want to create a simple form for my Time tracking utility.
This simple form has:
- Project name text input
- Description text input
- Notes text area
- Submit button
So, I created a Project controller class with an edit() function, and added the following method:
function edit()
{
$this->load->library('form');
$this->form->open('project/edit', 'project_edit_form')
->fieldset('Project')
->text('name', 'Project Name', 'max_length[40]')
->text('description', 'Description', 'max_length[40]')
->textarea('notes', 'Notes', 'trim', "Write your project notes here")
->indent(150)
->submit('Submit', 'sub')
->onsuccess('redirect', 'project/index')
->nobr();
$this->data['form'] = $this->form->get();
$this->data['errors'] = $this->form->errors;
$this->load->view('project/edit', $this->data );
}
Then, we need to create the view. For that purpose, I created the edit.php file under application/view/project folder.
<?php
Header('Cache-Control: no-cache');
Header('Pragma: no-cache');
$this->load->view('header', $data);
?>
<h2
>
Project</h2>
<?php echo $form ?>
<?php
$this->load->view('footer', $data);
?>
The important code line there is only <?php echo $form ?>
since it displays the form we previously generated. However, the other
pieces of code display a generic header and footer part, you can
discard that for your tests.
just need to open your browser, for example at: http://localhost/project/edit
to see the results.
By using this Form Generation library
you can create advanced forms,
too. For example you can create forms that use checkboxes, radio
buttons, multiple lists, etc. I’d recommend to download the library
including CI and user guide, from here
and look for views/welcome.php example to see an advanced version.
分享到:
相关推荐
2、CodeIgniter 1.7.1 用户指南 本书详细讲解了 CI 的一些主要特性。本书并不包含 CI 的所有内容和全部细节。CI 有一本出色的在线《用户指南》,它详细讲解了大多数的内容。它可以与 CI 一起下载。 本书并不想重复...
大多数PHPer都想写出运行状态良好的应用程序,而且希望尽可能做得简单且不费事。这篇文章是有关 CodeIgniter 的(以下简称 CI),CI 是一个达成以上目标的框架。 如果你只是要达成一个最终的结果,而把中间所有的...
一个简单的Codeigniter用户登录验证例子程序,支持session,密码加密存储,供初学者参考。
基于Ion Auth的Codeigniter的Active Directory身份验证 此软件可以与Codeigniter 3一起使用,以针对Active Directory域控制器(或Samba4域控制器)进行身份验证。 该软件旨在在Intranet上使用。 安装 确保您使用的...
它的目标是通过提供一组用于执行常见任务的库以及一个简单的界面和逻辑结构来访问这些库,从而使您比从头开始编写代码时更快地开发项目。 CodeIgniter使您可以最大限度地减少给定任务所需的代码量,从而创造性地...
CodeIgniter自述文件的简单缓存 由开发,并根据GNU通用公共许可证发行(请参阅LICENSE)。 关于 用于CodeIgniter的简单缓存是基于GNU通用公共许可证发行的基于开源文件的片段缓存库。 它被设计为易于使用,并且很...
aad-sso-codeigniter 使用Azure Active Directory对CodeIgniter站点进行身份验证重要提示:这尚未验证令牌,因此绝对不能使用。 使用Azure Active Directory保护对基于CodeIgniter PHP框架的网站或应用程序的访问。 ...
主要介绍了CodeIgniter表单验证方法,结合实例形式详细分析了CodeIgniter进行表单验证的具体步骤与相关实现技巧,需要的朋友可以参考下
博客 CodeIgniter 网站
## 指示:1 首先你必须在创建一个免费帐户并获取一个密钥并更改类(应用程序/库/Geoip)中 $_key 的值,你可以使用我为你,但我不确保它总是有效。 必须先在创建一个免费账号,在类(application/libraries/Geoip)...
框架的路由、中间件支持、身份验证工具等 - 来自印度尼西亚程序员的用于构建 Web 应用程序的完整平台。 使用 Codeigniter 3 构建 - Codeigniter 启动器 + + 内容管理系统 - 平面文件 CMS。 - 高级网站的内容管理系统...
CodeIgniter:开源PHP框架(最初来自EllisLab)
Ajax-Codeigniter-3-Ajax-Form-Submission.zip,“codeigniter 3 ajax表单提交和验证教程”一集的源代码,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于创建...
表单验证+对话框+日期格式化+日期选择框+select美化js框架
我们将安装CodeIgniter,创建一个CodeIgniter控制器和一个CodeIgniter视图。 然后,我们将使用路由器将控制器绑定到视图。 如果您迷失了方向,则可以在下面的仓库找到整个项目的源代码。 让我们开始吧。 ##安装从...
它的目标是通过提供一组用于执行常见任务的库以及一个简单的界面和逻辑结构来访问这些库,从而使您比从头开始编写代码时更快地开发项目。 CodeIgniter使您可以最大限度地减少给定任务所需的代码量,从而创造性地...
// Load library in your controller $this->load->library('infiqr'); // Call Infiqr and pass the content to simply generate image output in your controller $this->infiqr->generate('Hello, testing ...
Codeigniter的面包屑 轻量级Codeigniter库,用于生成HTML面包屑 用法 易于理解和使用的库是编写此库时的主要考虑因素之一。 从这个意义上讲,使用这个简单的库可以轻松应对,从添加和更新配置文件到加载库和用法。 ...
blog_codeigniter 博客高级编程BTS SIO2èmeannéeavec CodeIgniter 通过un projet de Blog simpliste启动àCodeIgniter 亲缘关系 WAMP堆栈: PhpMyAdmin v5.0.2 MySql v5.7.31 阿帕奇:2.4.46 PHP v7.3.21 ...
USPS Codeigniter 库与 USPS 运输和地址验证 API 集成的 Codeigniter 库安装将内容解压到您的系统文件夹中。 编辑 /application/config/usps.php 并将“user_id”更改为您注册 WebTools 帐户时由 USPS 提供的用户 ID...