Book Image

Instant Building Multi-Page Forms with Yii How-to

By : Uday Sawant
Book Image

Instant Building Multi-Page Forms with Yii How-to

By: Uday Sawant

Overview of this book

Yii is a high-performance PHP framework for rapid web application development. It is well-designed, well-supported, easy to learn, and easy to maintain. Forms are the basic method used to collect information on the Internet, and in cases like user registration and payment process, there's a lot of data to be presented and the lists can get lengthy. Instant Building Multi-Page Forms with Yii is a simple and descriptive how-to that provides step-by-step recipes to help you in converting your lengthy forms into short, interactive forms. It will guide you through the inbuilt features of Yii framework to help you with this complex job. The book starts with the basics of Yii and will guide you through creating simple forms before then converting your simple forms into multi-page forms. It will use the capabilities of Yii to ease the tasks required to do this. Yii eases your work by providing options like database connectivity. We will also take a look at the automated code generation capabilities of Yii in generating forms and necessary CRUD operations, as well as looking at how to divide a single long form into multiple views with same controller/action, and then add form validations and AJAX support to the forms. We will also cover the upload process and how to customise Yii's looks.
Table of Contents (7 chapters)

Preface

Instant Building Multi-Page Forms with Yii How-to is a simple and descriptive how-to that provides step-by-step recipes to help you convert your lengthy forms into short, interactive forms. It will show you the inbuilt features of the Yii framework to help you with this tricky task.

What this book covers

Getting started with Yii (Simple) helps you set the Yii environment and create a skeleton of the Yii application.

Connecting to the database (Simple) shows you how to set up a database connection in the Yii application.

Using the Gii tool (Simple) covers the automated code generation features provided by Yii. We will learn how to enable the Gii tool and create Models, CRUD, forms, and application modules.

Creating basic forms (Simple) helps you to create a basic single page form with Yii.

Building multipage forms (Intermediate) shows you how to split your lengthy single page form into multipage forms by validating the form fields and maintaining page data on each page.

Validating forms (Intermediate) gives you details on the form field validation helpers provided by Yii. We will look at various validation helpers, use validation rules provided by Yii, and set our own validation rules.

AJAX forms (Advanced) helps you enable AJAX support for forms. We will take a look at the AJAX helpers provided by Yii, AJAX-based form field validations, and AJAX-based form submission.

Uploading files (Advanced) covers the file upload features provided by Yii. We will look at how to file field validations and restrict uploads to specific file types.

Using multiple models (Intermediate) helps you learn the use of multiple models in a single form.

Customizing looks (Advanced) shows you the options provided by Yii to customize the look of forms. Additionally, we will learn how to create and use skins and customize widgets using the widget factory.

What you need for this book

To use the recipes, tips, and tricks of this book, you need to have the following:

  • A web server (any web server with plugins to process PHP scripts)

  • PHP version 5.2 + (5.3 recommended)

  • A database server (the book has been written with MySQL in mind, but you can easily choose a relational database server of your choice)

  • Yii Framework

Who this book is for

This book is great for developers who have a basic understanding of the Yii framework and want to learn about the advanced inbuilt features of Yii. It assumes that the reader has a basic knowledge of PHP development, the working of forms, and AJAX operations.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: " As we need the same form elements in actionCreate and actionUpdate, Yii has created a single file _form.php that contains all the form elements."

A block of code is set as follows:

'modules'=>array(
  // uncomment the following to enable the Gii tool
  /*
  'gii'=>array(
    'class'=>'system.gii.GiiModule',
    'password'=>'root',
    // If removed, Gii defaults to localhost only. Editcarefully to taste.
    'ipFilters'=>array('127.0.0.1','::1'),
  ),  */  
),

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

'modules'=>array(
  // uncomment the following to enable the Gii tool
  /*
  'gii'=>array(
    'class'=>'system.gii.GiiModule',
    'password'=>'root',
    // If removed, Gii defaults to localhost only. Editcarefully to taste.
    'ipFilters'=>array('127.0.0.1','::1'),
  ),  */  
),

Any command-line input or output is written as follows:

yii> framework/yiic  webapp  webRoot/sampleapp

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.