[PHP] CodeIgniter learning Manual (5): Application tutorial of Form auxiliary function Form

Source: Internet
Author: User
Tags codeigniter
Use the following code to load the auxiliary function: $ this-load-helper (form); form_open () allows you to add some form attributes and some hidden forms, and it will be based on your config. the encoding set in the PHP file automatically generates the accept-charset attribute. This function is used instead of directly hardcoded HTML.

Use the following code to load the auxiliary function: $ this-load-helper ('form'); form_open () allows you to add some form attributes and some hidden forms, and it will be based on your config. the encoding set in the php file automatically generates the accept-charset attribute. This function is used instead of directly hardcoded HTML.

Load auxiliary functions
Use the following code to load the Helper function:
$this->load->helper('form');


Form_open ()

Allow you to add some form attributes and some hidden forms, and automatically generate the accept-charset Attribute Based on the encoding set in your config. php file. The main advantage of using this function instead of directly hardcoding HTML is that it enables convenient conversion of your program, if your URL changes.

The following is an example:
echo form_open('email/send');
In the preceding example, a form is created and submitted to your base URL with the "email/send" URI segment, as shown in the following code:



Form_prep ()
It allows you to safely use HTML characters (such as quotation marks) in form elements without worrying about cracking the form. Consider the following example:
$string = 'Here is a string containing "quoted" text.';
Because the above string contains quotation marks, the form is damaged. The form_prep () function converts HTML, so you can safely use:
 

Note: If you use any of the form auxiliary functions, data is automatically preprocessed, so there is no need to call this function. This function is required only when you manually create a form element.



Set_value ()
You can set the value of the input or textarea field. You must specify the field name in the first parameter. The second parameter is optional. You can set a default value for the field. For example:
 

When the preceding form element is loaded for the first time, "0" is displayed ".



Set_select ()
If you use Drop-down menu. This function allows you to display the selected menu items. The first parameter must contain the name of the drop-down menu, and the second parameter must contain the value of each menu item. The third parameter is optional. It is used to set the menu item to the default selected status (use the TRUE/FALSE Boolean value ).Example: > One > Two > Three


Set_checkbox ()

Allows you to display a submitted check box. The first parameter must contain the name of this check box, the second parameter must contain its value, and the third parameter is optional, the function is to set the check box to the default selected status (use the TRUE/FALSE Boolean value ). For example:
 /> />


Set_radio ()

Allows you to display the submitted tickets. This function is the same as set_checkbox.

 /> />

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.