To do a Form we may create a div_table and put every element of the form in a div_td.
So, we will have a nice form. For the errors we may create some divs with the same name
of the input field + "_Error" and in case of error fill them with the error msg from the $_SESSION.
We may use the same form for the registration and modifying.
On modifying the field will get the "value" from the database, and in case of a new post + an eventual error captcha
we should populate the form fields not from the database but from the last modifying of user that is not yet stoder in db,
so from the $_SESSION.
This is easy too, but there is much code to write.
BHBSoft try to reduce this code, but not to minimalize it.
So we give to us the posibility to keep easy to understand and modify.
//to open a form print \BHB::$qform->open( array( "action" => "".\BHB::$url."c_user__opt__new_or_modify_login", "method" => "post", "id" => "nmulg", //is bhbidform too. "secure" => "", "goback" => "", //"", will get the actual position else put a r_xxx or a c_xxx. ) ); //Below there is the list for the type of input in BHBSoft: \BHB::$qform->input(); \BHB::$qform->inputm(); //for the array, m means multi. //text, password, hidden, button, image. \BHB::$qform->checkbox(); \BHB::$qform->checkboxm(); //for the array, m means multi. \BHB::$qform->select(); \BHB::$qform->select(); //for the array, m means multi. \BHB::$qform->radio(); \BHB::$qform->textarea(); \BHB::$qform->autocomplete(); \BHB::$qform->selectCascade(); //from a select to fill with jQuery an other select //to closse a form: //1. simple print \BHB::$qform->close("nmulg"); //2. to load the errors (if there are) after the post. print \BHB::$qform->closeAndShowErrorAfterPost( "nmulg", //is the idForm. In the form follow "_" and the id of input field: eg. nmulg_login. //the name of in put is the same, the div for error msg add "Error": eg nmulg_loginError. "GET", array( "input" => array( "addEffect" => array(".addClass('inputError')"), //where is made blur. "removeEffect" => array(".removeClass('inputError')") //where is made blur. ), //to fill idErrors with the error messages of php session var, when the user comes back on the page of form too. "idElement" => array( //where is the idInputOnBlurAddError ".css('display','block')", ".css('background','#dadada')" ), ), //for default bhb fill the element through append(msgError), but you may add an other css element. "* ", "<br style=\'clear:right;\'/>" ); //3. to load the errors from jQuery Ajax, too. print \BHB::$qform->closeAndShowErrorAfterPostAndJQAjax( "nmulg", //is the idForm. In the form follow "_" and the id of input field: eg. nmulg_login. //the name of in put is the same, the div for error msg add "Error": eg nmulg_loginError. "GET", array( "input" => array( "addEffect" => array(".addClass('inputError')"), //where is made blur. "removeEffect" => array(".removeClass('inputError')") //where is made blur. ), //to fill idErrors with the error messages of php session var, when the user comes back on the page of form too. "idElement" => array( //where is the idInputOnBlurAddError ".css('display','block')", ".css('background','#dadada')" ), ), //for default bhb fill the element through append(msgError), but you may add an other css element. "* ", "<br style=\'clear:right;\'/>" );
Lets test every element of input.
As you may see we have preserved the normal thml standard.
//INPUT print "<br />".\BHB::$qform->input( array( "type" => "text", //password, hidden, button, image. "id" => "nmulg_login", "style" => "width:70px;vertical-align:top;", "class" => "inputNormal", ), $res["login"] //this is the value that arrive from the sql query. ); //INPUTm //$inputMArray = array("fieldOne", "fieldTwo", "", "fieldFour"); $inputMArray = explode(";", $res["names"]); //from the db. for($i=0;$i<4;$i++){ print ($i+1).". ".\BHB::$qform->inputm( array( "type" => "text", "id" => "nmulg_names_".$i, "name" => "nmulg_names[]", "value" => "ciao", "style" => "width:90px;vertical-align:top;", ), $i ,$inputMArray )."<br /><br />"; } //CHECKBOX print \BHB::$qform->checkbox( array( "id" => "nmulg_confirm", "name" => "nmulg_confirm", "value" => "1", "class" => "inputNormal", ),$res["confirm"] )." "; //CHECKBOXm //multiple, array type. print "dog".\BHB::$qform->checkboxm( array( "id" => "nmulg_animal_d", "name" => "nmulg_animal[]", "value" => "dog", "class" => "inputNormal", ) ,$fromDbAnimal )." "; print "cat".\BHB::$qform->checkboxm( array( "id" => "nmulg_animal_c", "name" => "nmulg_animal[]", "value" => "cat", "class" => "inputNormal", ) ,$fromDbAnimal )." "; //print "<hr>"; print_r($_SESSION["form"]["nmulg"]["nmulg_animal"]); print "<hr>"; print "fish".\BHB::$qform->checkboxm( array( "id" => "nmulg_animal_f", "name" => "nmulg_animal[]", "checked" => "checked", "value" => "fish", "class" => "inputNormal", ) ,$fromDbAnimal )." "; print "rabbit".\BHB::$qform->checkboxm( array( "id" => "nmulg_animal_r", "name" => "nmulg_animal[]", "value" => "rabbit", "class" => "inputNormal", ) ,$fromDbAnimal )." "; //SELECT print \BHB::$qform->select( array( "id" => "nmulg_tfuel", "name" => "nmulg_tfuel", "class" => "inputNormal", "option" => array( "bhbnoselected" => "Select", "1" => "diesel", "2" => "gas", "7" => array("value"=>"4", "valuetxt"=>"electric", "selected"=>"selected"), "3" => "gpl", "100" => "hydrogen", ), ) ,$res["tfuel"] ); //SELECTm //from the db arrives 3 values if(\BHB::$login->isLogin("user")){ $resOddnumbersArray = explode(";", $res["oddnumbers"]); } $resON = \BHB::$db->query( \BHB::$db->db(), $sql="SELECT * FROM bhb_oddnumbers ORDER BY ord ASC" ,"array" //I expect an array response from db. So, $resOddNumbers is array. ); $optOddNumbers = array(); $optOddNumbers["bhbnoselected"] = "Select"; for($i=0; $i < count($resON["id"]); $i++) { if($resON["optvalue"][$i] == "k"){ //if this is selected by default. $optOddNumbers[$resON["optvalue"][$i]] = array("value"=>"k", "valuetxt"=>"3 - three", "selected"=>"selected"); }elseif($resON["optvalue"][$i] == "o6_1"){ //if this is selected by default. $optOddNumbers[$resON["optvalue"][$i]] = array("value"=>"o6_1", "valuetxt"=>"6 - six (bis)", "selected"=>"selected"); }elseif($resON["optvalue"][$i] == "o9"){ //if this is selected by default. $optOddNumbers[$resON["optvalue"][$i]] = array("value"=>"o9", "valuetxt"=>"9 - nine", "selected"=>"selected"); }else{ //only this is necessary for the $optOddNumbers to popolate the multi select. $optOddNumbers[$resON["optvalue"][$i]] = $resON["opttxt"][$i]; } } print \BHB::$qform->selectm( array( "id" => "nmulg_oddnumbers", "name" => "nmulg_oddnumbers[]", "multiple" => "multiple", "class" => "inputNormal", "option" => $optOddNumbers, //example from db. /* array( //example from php. "bhbnoselected" => "Select", //first position is default. "" no value is "Required" as response. If is required means that shouldn't be choice. "o1" => "1 - one", "o2" => "2 - two", "k" => array("value"=>"o3", "valuetxt"=>"3 - three", "selected"=>"selected"), "o4" => "4 - four", "o5" => "5 - five", "o6" => "6 - six", "j" => array("value"=>"o6_1", "valuetxt"=>"6 - six (bis)", "selected"=>"selected"), "o7" => "7 - seven", "o8" => "8 - eight", "o9" => array("value"=>"o9", "valuetxt"=>"9 - nine", "selected"=>"selected"), "o10" => "10 - ten", "o11" => "11 - eleven", ), */ ) ,$resOddnumbersArray ); //RADIO print \BHB::$qform->radio( array( "id" => "nmulg_gender_no", "name" => "nmulg_gender", "value" => "bhbnoselected", "class" => "inputNormal", ),$res["gender"] )."bhbnoselected"; print "<br />Male:".\BHB::$qform->radio( array( "id" => "nmulg_gender_m", "name" => "nmulg_gender", "value" => "m", "checked"=>"checked", "class" => "inputNormal", ),$res["gender"] ); print " Female:".\BHB::$qform->radio( array( "id" => "nmulg_gender_f", "name" => "nmulg_gender", "value" => "f", "class" => "inputNormal", ),$res["gender"] ); //********Start Select Cascade **************** //SELECT on CASCADE //CONTINET print \BHB::$qform->select( array( "id" => "nmulg_one", "class" => "inputNormal", "option" => array( "bhbnoselected" => "Select", "1" => "Europe", "2" => "America", "3" => "Asia", ), "style" => "width:90px;", //"addOption"=> $objSelectOpt -> formLanguageOpt(), "doNotCloseSelect" => "", //becouse I will close the select by me. ) ,$res["select_one"] )."</select>"; //STATE print \BHB::$qform->select( array( "id" => "nmulg_two", "class" => "inputNormal", "option" => array( "bhbnoselected" => "Select", ), "style" => "width:90px;" ) ,array($res["select_two"] => \BHB::$db->selectRow("", "state", "bhb_states", "id", $res["select_two"])) //,array($res["select_two"] => $stat[$res["select_two"]]) //here we need to give an associative array("RealValue"=>"valueText") //<value="RealValue" checked>ValueText</option> ); //REGION print \BHB::$qform->select( array( "id" => "nmulg_three", "class" => "inputNormal", "option" => array( "bhbnoselected" => "Select", ), "style" => "width:90px;" ) //,array($res["select_three"]=>$regi[$res["select_three"]]) ,array($res["select_three"] => \BHB::$db->selectRow("", "region", "bhb_regions", "id", $res["select_three"])) ); //CITY print \BHB::$qform->select( array( "id" => "nmulg_four", "class" => "inputNormal", "option" => array( "bhbnoselected" => "Select", ), "style" => "width:90px;" ) //,array($res["select_four"]=>$city[$res["select_four"]]) ,array($res["select_four"] => \BHB::$db->selectRow("", "city", "bhb_cities", "id", $res["select_four"])) ); //WE NEED NOW TO CONNECT THEM THANKS jQuery. \BHB::$qform->selectCascade( "nmulg", array( //the idOfSelects => (nameVarOfSelectValurToSendIntoPHPFile) "nmulg_one" => array("change" => "nmulg_two", "get" => "c_user__test_select__test_cascade/index.php?a=1a_IfYouNeed", // index.php is a convenction "varName" => "continent", //to send in your php script: jQuery will get its value by id nmulg_one. ), "nmulg_two" => array("change" => "nmulg_three", "get" => "c_user__test_select__test_cascade/index.php?b=2b_IfYouNeed", "varName" => "state", //to send in your php script: jQuery will get its value by id nmulg_two. ), "nmulg_three" => array("change" => "nmulg_four", "get" => "c_user__test_select__test_cascade/index.php?c=3c_IfYouNeed", "varName" => "region", ), "nmulg_four" => array("change" => "", "get" => "c_user__test_select__test_cascade/index.php?d=4d_IfYouNeed", "varName" => "", ) ) ); //AND WE SHOULD WRITE c_user__test_select__test_cascade/index.php to lselect and load the various state, region or city. namespace user\controller\test_select; class test_select { public function test_cascade() { //the States if($_REQUEST["continent"]) { $resState = \BHB::$db->query( \BHB::$db->db("basilar"), $sql = "SELECT * FROM bhb_states WHERE idcont = '".mysql_real_escape_string($_REQUEST["continent"])."'", "array" ); ?> <option value="bhbnoselected" <?php print (\BHB::$form->getFormInputValue("nmulg","nmulg_two")=="bhbnoselected")?"selected":""; ?> >Select</option> <?php if(is_array($resState)) { for($i=0; $i<count($resState["id"]); $i++) { ?> <option value="<?php print $resState["id"][$i]; ?>" <?php print (\BHB::$form->getFormInputValue("nmulg","nmulg_two")==$resState["id"][$i])?"selected":""; ?> ><?php print $resState["state"][$i]; ?></option> <?php } } } //the Regions if($_REQUEST["state"]) { $resRegion = \BHB::$db->query( \BHB::$db->db("basilar"), $sql = "SELECT * FROM bhb_regions WHERE idstate = '".mysql_real_escape_string($_REQUEST["state"])."'", "array" ); ?> <option value="bhbnoselected" <?php print (\BHB::$form->getFormInputValue("nmulg","nmulg_three")=="bhbnoselected")?"selected":""; ?> >Select</option> <?php if(is_array($resRegion)) { for($i=0; $i<count($resRegion["id"]); $i++) { ?> <option value="<?php print $resRegion["id"][$i]; ?>" <?php print (\BHB::$form->getFormInputValue("nmulg","nmulg_three")==$resRegion["id"][$i])?"selected":""; ?> ><?php print $resRegion["region"][$i]; ?></option> <?php } } } //the Cities if($_REQUEST["region"]) { $resCity = \BHB::$db->query( \BHB::$db->db("basilar"), $sql = "SELECT * FROM bhb_cities WHERE idregion = '".mysql_real_escape_string($_REQUEST["region"])."'", "array" ); ?> <option value="bhbnoselected" <?php print (\BHB::$form->getFormInputValue("nmulg","nmulg_four")=="bhbnoselected")?"selected":""; ?> >Select</option> <?php if(is_array($resCity)) { for($i=0; $i<count($resCity["id"]); $i++) { ?> <option value="<?php print $resCity["id"][$i]; ?>" <?php print (\BHB::$form->getFormInputValue("nmulg","nmulg_four")==$resCity["id"][$i])?"selected":""; ?> ><?php print $resCity["city"][$i]; ?></option> <?php } } } } } //*******END Slect Cascade************** //TEXTAREA print \BHB::$qform->textarea( array( "id" => "nmulg_aboutme", "cols" => "90", "rows" => "15", ) ,$res["aboutme"] );