Author: Murat ATAK
Bootstrap : getbootstrap.com
Sweet Alert : t4t5.github.io/sweetalert
DataTables : datatables.net
Select2 : select2.github.io
iCheck : icheck.fronteed.com
JQUERY : jquery.com
Inputmask: github.com/RobinHerbots/Inputmask
PHP: php.net
OR USE METRONIC FOR FULL ASSETS WITH MFORM LIBRARY
Metronic assets : keenthemes.com/preview/metronic
echo MForm::attribute("value")->element("name","value");
echo MForm::[all html attributes]->element("name","value");
example:
echo MForm::id("element")->icon("fa fa-user")->[... ETC ...]->text("name","");
echo MForm::element("name","value",[
"attribute-name" => "value",
"attribute-name2" => "value",
... ETC ...
]);
example:
echo MForm::text("name","value",[
"data-toggle" => "tooltip",
"icon" => "fa fa-user",
"id" => "TEXT",
"style" => "color:red",
... ETC ...
]);
echo MForm::col(4)->text("text1","");
echo MForm::col(4)->text("text2","");
echo MForm::col(4)->text("text3","");
echo MForm::col(6)->text("text1","");
echo MForm::col(6)->text("text2","");
echo MForm::id("iconInput")->[..all html attributes..]->icon("fa fa-user")->iconalign("left")->text("name","default value");
echo MForm::id("iconButton")->[..all html attributes..]->icon("fa fa-user")->iconalign("left")->button("name","default value");
echo MForm::open("form");
.... OTHER ELEMENT ...
echo MForm::close();
echo MForm::validate(true)->open("form");
echo MForm::material(true)->validate(true)->open("form");
echo MForm::validate(true)->ajax([
"url"=>"http://..",
"datatype"=>"JSON",
"method"=>"POST",
"callback"=>"4",
"callbackurl"=> "http://.."
])
->material(false)->id("form1")->onsubmit("return false;")->open("form1");
Param | Description |
---|---|
1 | Return message on class="alert alert-success" |
2 | clear body and set message on body |
3 | show sweet alert |
4 | Show in #globalModal |
**4 *** | this have callbackurl param! |
for the "#globalModal" go to this line > What is the globalModal ?
callbackurl: (for callback params : 4)
load custom modal content in the your php file
- You'll write all validation rules
echo MForm::required("")->min("5")->max("12")->text("number","");
echo MForm::template("light")->title("PORTLET TİTLE")->open("portlet");
.... OTHER ELEMENTS ....
echo MForm::close("portlet");
echo MForm::clearFix();
Info
- Your php file will be return "true" or "false"
- " Class name is required "
echo MForm::checktext("http://myphpfile.php")->class("INPUT_CLASS")->label("USERNAME:")->text("USERNAME","");
php code:
DB:...()->..;
if($recordisvalid)
echo "true"; //record is valid, show error
else
echo "false"; //record is not valid, hide error
$opt = ["VAL1" => "TEXT1","VAL2" => "TEXT2", "SELECTED" => "TEXT2"];
echo MForm::options($opt)->id("SELECT2_ID")->label("SELECT2 LABEL")->select2("SELECT2_NAME","");
Select2 with trigger (posting selected value to your ajax url and append new options in your target element)
$opt = ["VAL1" => "TEXT1","VAL2" => "TEXT2", "SELECTED" => "TEXT2"];
$triggerOptions = ["ajaxurl" => "POST URL", "target" => "#TARGET_SELECT2_FOR_LOAD_NEW_OPTIONS"];
echo MForm::trigger($triggerOptions)->options($opt)->id("SELECT2_ID")->label("SELECT2 LABEL")->select2("SELECT2_NAME","");
What is this ? > Watch swf
$triggerForm =
[
"data" =>
[
0 => ["target" => ".ELEMENT1", "data" => "Array | Json Key"],
1 => ["target" => ".ELEMENT2", "data" => "Array | Json Key"]
],
"ajaxurl" => "http://" //this link will be return $db->...()->row();
];
SOURCE SELECT2:
echo MForm::col(4)->required("required")->triggerForm($triggerForm)->class("select2")->id("ID")->label("LABEL")->select2("NAME", "");
TARGET ELEMENTS:
echo MForm::col(4)->required("required")->class("ELEMENT1")->label("TARGET ELEMENT 1")->text("ELEMENT1","");
echo MForm::col(4)->required("required")->class("ELEMENT2")->label("TARGET ELEMENT 2")->text("ELEMENT2","");
echo MForm::close("element");
output:
</element>
echo MForm::close();
output:
</form>
echo MForm::count(2)->close("div");
output:
</div></div>
element => html, div, span, p, h1, h3, ...
echo MForm::modal(
[
"ajaxurl" => "Http://..", // link of your modal content
"close" => "true", //AFTER SUBMİT CLOSE MODAL
"refresh" => "false", // AFTER SUBMİT REFRESH PAGE
"width" => "modal-lg", // MODAL SİZE
"ajaxreload" => "true" // İF YOU USE DATATABLE SERVER SİDE THİS OPTİONS WİLL UPDATE YOUR TABLES
])
->id("BUTTON_ID")
->icon("fa fa-plus") //button icon
->class("btn btn-primary pull-right") //button class
->button("BUTTON_NAME", "BUTTON_TEXT");
<div class="modal-header">
<button type="button" class="close" aria-hidden="true"></button>
<h4 class="modal-title">TİTLE</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
CONTENT
</div>
</div>
</div>
<div class="modal-footer">
FOOTER BUTTONS ETC..
</div>
you need to include globalModal in your master page. MForm working with this modal skeleton
<div id="globalModal" data-backdrop="static" class="modal fade" tabindex="-1" data-width="400">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
@ https://datatables.net/examples/data_sources/server_side.html
$cols = array
(
"COL 1" => array("ICON" => "fa fa-calendar" , "SHOW" => "ALL"),
"COL 2" => array("ICON" => "fa fa-object-group" , "SHOW" => "MOBILE") // DESKTOP
);
echo MForm::dom("") //Datatable buttons
->ajaxurl("server side url")
->table("table_1", $cols);
echo MForm::col(4)->class("time")->label("TIME:")->icon("fa fa-calendar")->time("time", "", ["showMeridian" => "true" , ... OTHER ATTRIBUTES]);
echo MForm::col(4)->class("date")->label("DATE:")->icon("fa fa-calendar")->date("date", "", ["endDate" => "+0d" , ... OTHER ATTRIBUTES]);
echo MForm::col(4)->class("datetime")->label("DATE TIME:")->icon("fa fa-calendar")->datetime("datetime", "", ["endDate" => "+0d" , ... OTHER ATTRIBUTES]);
## DATERANGE element usage:
echo MForm::col(4)->class("daterangepicker")->label("DATE RANGE:")->icon("fa fa-calendar")->daterangepicker("daterangepicker", "", ["endDate" => "+0d" , ... OTHER ATTRIBUTES]);
echo MForm::col(12)->label("CHECK ME!")->checkbox("NAME", "VALUE", ["checkboxClass" =>"icheckbox_square-green"]);
$checks = Array(
["name" => "CHCK[]", "value" => "21", "label" => "DİYARBAKIR", "checked" => "true"], // checked will be string "true"
["name" => "CHCK[]", "value" => "34", "label" => "İSTANBUL"]
);
echo MForm::col(12)->label("CHECK AN OPTION")->options($checks)->radio("NAME", "VALUE", ["radioClass"=>"iradio_square-green"]);
echo MForm::hidden("name","value");
echo MForm::select("name","value");
echo MForm::email("name","value");
echo MForm::tel("name","value");
echo MForm::textarea("name","value");
echo MForm::file("name","value");
echo MForm::color("name","value");
echo MForm::image("name","value");
echo MForm::url("name","value");
echo MForm::month("name","value");
echo MForm::number("name","value");
echo MForm::password("name","value");
echo MForm::search("name","value");
echo MForm::week("name","value");
echo MForm::time("name","value");
echo MForm::datetime("name","value");
echo MForm::datetimeLocal("name","value");
echo MForm::checkbox("name","value");
echo MForm::radio("name","value");
echo MForm::submit("name","value");
echo MForm::reset("name","value");
echo MForm::link("name","value");