Learning notes-multi-Data article page form submission and validation-2016.4.8

Source: Internet
Author: User

Because the article new or other data volume than the larger form of the new, we can first use a piece of data to complete the new, if successful, we copy the line to avoid errors!

HTML section

<form action= "# # #" method= "POST" id= "main" name= "Content" >
<table cellspacing= "0" class= "Content" >
<tr><th><strong> Publish a new document </strong></th></tr>
<tr><td> Document title: <input type= "text" name= "title" class= "text"/> <span class= "Red" >[required]</span > (* title 2-50 characters between) </td></tr>
<tr><td> section: <select name= "nav" ><option value= "" > Please select a column category </option>{$nav}</select > <span class= "Red" >[required]</span></td></tr>
<tr><td> Define properties: <input type= "checkbox" Name= "attr[]" value= "headline"/> Headlines
<input type= "checkbox" Name= "attr[]" value= "recommended"/> Recommended
<input type= "checkbox" Name= "attr[]" value= "bold"/> Bold
<input type= "checkbox" Name= "attr[]" value= "Jump"/> Jump
</td></tr>
<tr><td> Tags: <input type= "text" name= "tag" class= "Text"/> (* each label with ', ' separated, total length within 30 bits) </td></tr >
<tr><td> keywords: <input type= "text" name= "keyword" class= "text"/> (* each keyword with ', ' separated by a total length of 30 bits) </td>& Lt;/tr>
<tr><td> thumbnails: <input type= "text" name= "thumbnail" class= "text" readonly/>
<input type= "button" value= "Upload" onclick= "CenterWindow ('.. /templates/upfile.html ', ' upfile ', ' + ', ' max ') ' >
(* must be jpg,gif,png, size 200KB)
</td>
</tr>
<tr><td> article Source: <input type= "text" name= "source" class= "text"/> (* Article source 20 bits) </td></tr>
<tr><td> Author: <input type= "text" name= "author" class= "Text"/> (* author 10 bits) </td></tr>
<tr><td><span class= "middle" > Content summary: </span><textarea name= "Info" ></textarea> <span class= "Middle" > (* Content summary within 200) </span></td></tr>
<tr><td>
<!--loading the editor's container--
<script id= "Container" name= "Details" type= "Text/plain" ></script>
<!--configuration file--
<script type= "Text/javascript" src= ". /ueditor/ueditor.config.js "></script>
<!--editor source files--
<script type= "Text/javascript" src= ". /ueditor/ueditor.all.js "></script>
<!--instantiation Editor--
<script type= "Text/javascript" >
var UE = ue.geteditor (' container ');
</script>
</td>
</tr>
<tr><td> Comment options: <input type= "Radio" name= "commend" value= "1" checked= "checked"/> Allow comments
<input type= "Radio" name= "commend" value= "0"/> Forbidden Comment
PageView: <input type= "text" Name= "Count" value= "" "class=" text small "/>
</td></tr>
<tr><td> document Sort: <select name= "Sort" >
<option> default Sort </option>
<option> Top Day </option>
<option> one week </option>
<option> pinned January </option>
<option> One year </option>
</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; consumer coins: <input type= "text" name= "Gold" value= "0" class= "Text small"/>
</td></tr>
<tr><td> Read access: <select name= "Limit" >
<option> Open View </option>
<option> Junior Members </option>
<option> Intermediate Members </option>
<option> Senior Members </option>
&LT;OPTION&GT;VIP member </option>
</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; title color: <select name= "Color" >
<option value= "" > Default color </option>
<option value= "Red" style= "color:red;" > Red </option>
<option value= "Blue" style= "color:blue;" > Blue </option>
<option value= "Orange" style= "color:orange; "> Orange </option>
</select>
</td></tr>
<tr><td><input type= "Submit" name= "send" value= "Publish Document" onclick= "return checkaddcontent ()"/> < Input type= "reset" value= "reset"/></td></tr>
<tr><td></td></tr>
</table>
</form>

PHP Controller Section
Private function Add () {
if (isset ($_post[' send ')) {
if (Validate::checknull ($_post[' title '))) Tool::alertback (' Warning: Title must not be empty! ‘);
if (Validate::checklength ($_post[' title '],2, ' min ')) Tool::alertback (' Warning: Title length must not be less than two bits! ‘);
if (Validate::checklength ($_post[' title '],50, ' Max ')) Tool::alertback (' Warning: Title length must not be greater than 50 bits! ‘);
if (Validate::checknull ($_post[' nav '))) Tool::alertback (' Warning: A column must be selected! ‘);
if (validate::checklength ($_post[' tag '],30, ' Max ')) Tool::alertback (' Warning: Tag tag length must not be greater than 30 bit! ‘);
if (validate::checklength ($_post[' keyword '],30, ' Max ')) Tool::alertback (' Warning: The keyword length must not be greater than 30 bits! ‘);
if (Validate::checklength ($_post[' source '],20, ' Max ')) Tool::alertback (' Warning: article source length must not be greater than 20 bits! ‘);
if (Validate::checklength ($_post[' author '],10, ' Max ')) Tool::alertback (' Warning: Author length must not be greater than 10 bits! ‘);
if (validate::checklength ($_post[' info '],200, ' Max ')) Tool::alertback (' Warning: Content summary must not be greater than 200 bits! ‘);
if (validate::checknull ($_post[' details ')) Tool::alertback (' Warning: the details must not be empty! ‘);
if (Validate::checknum ($_post[' count '))) Tool::alertback (' Warning: The number of views must be a number! ‘);
if (Validate::checknum ($_post[' Gold ')) Tool::alertback (' Warning: Consumer coins must be numbers! ‘);
if (Isset ($_post[' attr ')) {
$this->model->attr = Implode (', ', $_post[' attr ');
}else{
$this->model->attr = ' no attributes ';
}
$this->model->title = $_post[' title '];
$this->model->nav = $_post[' nav ');
$this->model->tag = $_post[' tag ');
$this->model->keyword = $_post[' keyword ');
$this->model->thumb = $_post[' thumbnail ');
$this->model->source = $_post[' source ');
$this->model->author = $_post[' author ');
$this->model->info = $_post[' info '];
$this->model->content = $_post[' Details '];
$this->model->gold = $_post[' Gold ');
$this->model->commend = $_post[' commend ');
$this->model->count = $_post[' count '];
$this->model->color = $_post[' color '];
$this->model->addcontent ()? Tool::alert ("Document published successfully! ", '? Action=add '): Tool::alertback (' Document publishing failed! ‘);

}
$this->tpl->assign (' Add ', true);
$this->tpl->assign (' title ', ' New Document ');
Get the cascading drop-down menu
/*
* Use <optgroup></optgroup> group to get the main menu
* Re-content controller in the instantiation of the navigation model
*/
Initialize a variable
$htm = 0;
$nav = new Navmodel ();
$nav->getallchildnav ();
foreach ($nav->getallnav () as $object) {
$htm. = ' <optgroup label= "'. $object->nav_name. '" > '. ' \ r \ n ";
$nav->id = $object->id;
if (!! $childNav = $nav->getallchildnav ()) {
foreach ($childNav as $obj) {
$htm. = ' <option value= "'. $obj->id. '" > '. $obj->nav_name. ' </option> '. ' \ r \ n ";
}
}
$htm. = ' </optgroup> ';
}
$this->tpl->assign (' Nav ', $htm);
}

JS Verification Section
function Checkaddcontent () {
var fm = document.content;
if (Fm.title.value = = "| | Fm.title.value.length < 2 | | fm.title.value.length > 50) {
Alert (' Warning: the title must not be empty and must not be less than two bits and must not be greater than 50 bits! ‘);
Fm.title.focus ();
return false;
}
if (Fm.nav.value = = ") {
Alert (' Warning: A column must be selected! ‘);
Fm.nav.focus ();
return false;
}
if (Fm.tag.value.length > 30) {
Alert (' WARNING: Tag tag must not be greater than 30 bits! ‘);
Fm.tag.focus ();
return false;
}
if (Fm.keyword.value.length > 30) {
Alert (' WARNING: keyword must not be greater than 30 bits! ‘);
Fm.keyword.focus ();
return false;
}
if (Fm.source.value.length > 20) {
Alert (' Warning: Article source must not be greater than 20 bit! ‘);
Fm.source.focus ();
return false;
}
if (Fm.author.value.length > 10) {
Alert (' Warning: the author must not be greater than 10 bits! ‘);
Fm.author.focus ();
return false;
}
if (Fm.info.value.length > 200) {
Alert (' Warning: Content summary must not be greater than 200 bits! ‘);
Fm.info.focus ();
return false;
}
if (Fm.details.value = = ") {
Alert (' Warning: the details must not be empty! ‘);
Fm.details.focus ();
return false;
}
if (IsNaN (Fm.count.value)) {
Alert (' Warning: The number of views must be a number! ‘);
Fm.count.focus ();
return false;
}
if (IsNaN (Fm.gold.value)) {
Alert (' Warning: Consumer coins must be numbers! ‘);
Fm.gold.focus ();
return false;
}
return true;
}





Learning notes-multi-Data article page form submission and validation-2016.4.8

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.