首页
开发手册
应用中心
工具
用户中心
FoundPHP Validate Form Data
表单验证是在开发中非常重要的环节,FoundPHP提供非常简单的验证方式
English
中文简体
English
上一篇
下一篇
### FoundPHP Form Validation Form verification is a very important part of development. FoundPHP provides a very simple verification method. Set the table name and field data before the program starts. When the form is submitted, use the `post_data` method to verify the data. #### 1.Set Table Name ```php 'add'| | req | No | must fill in the corresponding function | If it is required to add a function, it is not necessary to fill in the edit:'req'=>'add'| | query | No | check whether the data in this field exists, like fuzzy search | To check:'query'=>'1'| | search | No | automatically create a search box | Search:'search'=>'1'| --- ##### Array Verification Check Usage | Usage | Description | | ------ | ------ | | =='' | validation when the character is equal to empty | | !='' | verification when the character is not equal to empty | | =='' && variable =='' | verification when the character is equal to empty and the variable is equal to empty (can continue to increase and or judge) | | id | ID number verification | | mobile | mobile phone number verification | | mail | email verification | | bank | bank card verification| --- #### 3.The Method of Using Post_data. After setting the validation array, use the `post_data` method to verify when the form is submitted. ```php //please drop down to see the example for the complete code $post = post_data($table['a'],$insert); ``` `post_data`The output of the method contains two arrays `data` and `check` `data`The output of the array is the verified data information, which can be directly inserted into the database using the dbo method. `check`The output of the array is the data information that needs to be verified with the database. When inserting the database using the dbo method, if there is duplicate data, no new data will be inserted. ##### Complete Code Example ```php array( 'lang' => lang('please enter[user name]'), 'ope' =>'trim', 'check' => '==""', 't' => 'add,edit', 'req' =>'add', 'query' =>'1', 'search' => '1' ), 'password' => array( 'lang' => lang('please enter[user password]'), 'ope' =>'trim', 'code' => 'md5', 'long' => '0,20', 'check' => '==""', 't' => 'add,edit', 'req' =>'add', 'query' =>'1', 'search' => '1' ), ); switch($t){ //edit case'edit': if($P['o']){ //use the post_data method to validate form data $post = post_data($table['a'],$insert); //edit data sql_update_insert(array('table'=>$table['a'],'data'=>$post['data'],'where'=>'condition')); } break; //add to case'add': if($P['o']){ //use the post_data method to validate form data $post = post_data($table['a'],$insert); //adding data sql_update_insert(array('table'=>$table['a'],'data'=>$post['data'],'check'=>$post['check'])); } break; //list default: } ```