It has been a while. I have decided to make baby steps on Fractured Nations: Tradewars. To do so I have been getting minor functionality out on Fractured Nations via small projects that have the same core dependencies as Tradewars. Thus I have something to show in the mean time of the major project.
The two pre-projects are Tic-Tac-Toe and an Uno variant called "I Got Two"
Check them out: https://www.fracturednations.com
This is a blog for me to keep my scripting notes in, if you like the code go ahead and copy it.
Monday, July 8, 2019
Wednesday, August 17, 2016
Just published my Ajax library. It is very much like jQuery. In fact it is a micro library I built so I would not need to load up jQuery. It comes bundled with FN_Deferred. I admit it is not as full featured as FN_Deferred, but it is very much like jQuery Ajax, and could be the replacement you are looking for.
Go micro, Go Fast.
https://github.com/josephtveter/FN_AjaxTuesday, August 16, 2016
I just published my micro Promise A Library.
If you are looking for a micro library for your Deferred Objects look no further. This library was built to support Promise A, can easily replace jquery deferred if you are wanting to lighten the load on your site, and unlike window.Promise it can handle multiple arguments to callbacks. All that and it weighs in about 3kb. Give it a try.
https://github.com/josephtveter/fn_deferred
Thursday, January 21, 2016
Fractured Nations Common JS Library
After using several Common JS libraries for dependency management I decided that none of them offered me all the things I wanted. I wanted small and fast like Require. I also wanted to load modules like Node and Inject with module.exports. I wanted modules to preload ahead of execution. I also wanted easy path rewrite abilities that Inject offered. And I wanted it easy to understand. So last summer I started building my own.
I give you Fractured Nations Common JS. It is a Common JS dependency management library with Deferred Promises, Ajax and custom logging. The Common JS supports require, module.exports, and define. The Deferred Promises support then, done, fail, always, resolve, and reject to be compliant with Promise/A and the Jquery standard if you are in the mood to ditch Jquery. The Ajax library is similar to Jquery but is not very developed. The logging allows you to turn it on and off and set how much logging you desire for certain parts of the code.
Give it a spin. There are several examples, including a fully working site that has knockout.js enabled.
https://github.com/josephtveter/fn_common
Sunday, October 12, 2014
Alpha Build
I just got my personal framework to Alpha build. It works... mostly but there is not much to it.
The main focus of it is to make fast and easy web applications that scale. It will be the base framework for my web games. If your into web applications and want to check out a cool Common JS framework, I am offering the Alpha Build free on my site.www.fracturednations.com
If you want to see it working, its not much, but it works. Here are two demo sites that I am putting together.
www.fracturednations.info
system.fracturednations.info
Joseph Tveter
www.fracturednations.com
The main focus of it is to make fast and easy web applications that scale. It will be the base framework for my web games. If your into web applications and want to check out a cool Common JS framework, I am offering the Alpha Build free on my site.www.fracturednations.com
If you want to see it working, its not much, but it works. Here are two demo sites that I am putting together.
www.fracturednations.info
system.fracturednations.info
Joseph Tveter
www.fracturednations.com
Wednesday, July 30, 2014
Geolocation woes
Apparently HTML5 has an api to get me exactly where I am on the planet. But it can't tell me what country I am in. Google will tell me. Google knows all.
this.getGeoLocation = function()
{
var deferred = $.Deferred();
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
deferred.resolve(position);
//position: {"coords":{"speed":null,"accuracy":65,"altitudeAccuracy":10,"altitude":1410.8349609375,"longitude":-111.72789187811416,"heading":null,"latitude":40.332329714635044},"timestamp":1406740874211}
});
}
else
{
deferred.reject({error: "FAIL"});
}
return deferred.promise();
};
this.getGeoLocation = function()
{
var deferred = $.Deferred();
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
deferred.resolve(position);
//position: {"coords":{"speed":null,"accuracy":65,"altitudeAccuracy":10,"altitude":1410.8349609375,"longitude":-111.72789187811416,"heading":null,"latitude":40.332329714635044},"timestamp":1406740874211}
});
}
else
{
deferred.reject({error: "FAIL"});
}
return deferred.promise();
};
Wednesday, July 2, 2014
Wait for it....
Deferred Objects with jquery. Great for when you are waiting for data to process or servers to reply.
var deferredData = $.Deferred();
deferredData.done(function(result)
{
//do stuff
}).fail(function(errorObj)
{
//handel error
}).always(function(result)
{
//whatever is returned comes here as well.
});
// when the data is done simply call
deferredData.resolve(result);
//or if you want to fail
deferredData.reject(errorObj);
var deferredData = $.Deferred();
deferredData.done(function(result)
{
//do stuff
}).fail(function(errorObj)
{
//handel error
}).always(function(result)
{
//whatever is returned comes here as well.
});
// when the data is done simply call
deferredData.resolve(result);
//or if you want to fail
deferredData.reject(errorObj);
Tuesday, January 7, 2014
Web page scaling to the device!
Web page scaling to the device! Even with different pixel ratios! Will work with android, iPhone and web!
Enjoy!
var dpi = window.devicePixelRatio || 1;
var width = $(window).width();
var ratio = 52; //Ratio of target font size to screen width screenWidth/idealFontSize
var font = Math.ceil((width / dpi / ratio)+dpi*3);
if(font < 15)
font = 15;
// any less is not useable.
$("html").css({"fontSize": font});
Enjoy!
Saturday, November 9, 2013
Cookie Module and Common JS
With the slow death of flash I have decided to build my game on a javascript MVC framework. The core is using the Common JS library Inject.
This mornings project was creating a cookie manager. I stole and modified some basic cookie functions from W3Schools, and put it into the Common JS structure. Happy Scripting.
Here is the code to call it.
////////////////////////////////////////////////////
var Cookie = require("modules.model.Cookie");
var App = function()
{
this.Cookie = new Cookie();
//set the cookie
this.Cookie.setCookie("UserName", "Bob");
//Get the cookie
var userName = this.Cookie.getCookie("UserName");
alert("Username = " + userName);
//is the cookie
var isUser = this.Cookie.isCookieValue("UserName", "Bob");
alert("Is Bob the User? " + isUser);
};
///////////////////////////////////////////////////
Here is the module
/////////////////////////////////////////////////
var Cookie = function()
{
var self = this;
this.DEFAULT_EXP = 30; //days
this.setCookie = function(c_name,value,exdays)
{
var exdate=new Date();
if(!exdays)
{
exdays = self.DEFAULT_EXP;
}
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
};
this.getCookie = function(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
};
this.isCookieValue = function(name, value)
{
debugger;
var cookie = self.getCookie(name);
if(cookie===null || cookie==="")
{
return false;
}
else
{
if(cookie === value)
{
return true;
}
else
{
return false;
}
}
};
};
module.exports = Cookie;
///////////////////////////////////////////////
This mornings project was creating a cookie manager. I stole and modified some basic cookie functions from W3Schools, and put it into the Common JS structure. Happy Scripting.
Here is the code to call it.
////////////////////////////////////////////////////
var Cookie = require("modules.model.Cookie");
var App = function()
{
this.Cookie = new Cookie();
//set the cookie
this.Cookie.setCookie("UserName", "Bob");
//Get the cookie
var userName = this.Cookie.getCookie("UserName");
alert("Username = " + userName);
//is the cookie
var isUser = this.Cookie.isCookieValue("UserName", "Bob");
alert("Is Bob the User? " + isUser);
};
///////////////////////////////////////////////////
Here is the module
/////////////////////////////////////////////////
var Cookie = function()
{
var self = this;
this.DEFAULT_EXP = 30; //days
this.setCookie = function(c_name,value,exdays)
{
var exdate=new Date();
if(!exdays)
{
exdays = self.DEFAULT_EXP;
}
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
};
this.getCookie = function(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
};
this.isCookieValue = function(name, value)
{
debugger;
var cookie = self.getCookie(name);
if(cookie===null || cookie==="")
{
return false;
}
else
{
if(cookie === value)
{
return true;
}
else
{
return false;
}
}
};
};
module.exports = Cookie;
///////////////////////////////////////////////
Saturday, August 17, 2013
Singleton vrs Dependency Injection.
I have been starting to nail down the framework for my game. I have been reviewing my php knowledge base, on how to solve global variable, and object issues. I have friends that have been using singleton classes, and I defiantly see where they are going with it. It is handy for making sure you only have one instance of the thing running around, especially if you are dealing with a single object such as a web user.
But I just don't feel it is the right solution for me. I think I am going to go more toward dependency injection at the bootstrap. My controller structure extends each other based on the page. So the sub page of a sub page will have been extended with each page all the way back to the main site controller. And any additional needed dependencies can be loaded for a new sub page controller. I can see going singleton if you have more then 1 controller object, which I have seen that approach before but it seemed cumbersome. I don't like cumbersome. I think it will be one controller that has been extended from the root, with dependency injection. Seems like it would be cleaner.
Saturday, July 20, 2013
Web Programmer, Tech Levels
Web Programmer, Tech Levels
What do you mean by Senior Web Programmer? After spending several years in the web development field, I think there needs to be a clarification on what a Senior Web Programmer is. I have met people who's scripting ability is nothing less then beyond mortal. And I have met some "Senior Programmers" who have code so dirty that it might be likened to a mud pit. So I present to the general population of the world and, anyone else who might care a better scale to rate people on then Jr, and Sr, programmers.Wanaabe
Yes I have built a website and it was legit. I used a website builder and even went in to the code and added a <br>
Neophyte
I took some classes/read some books and learned html. I use Dreamwaever, Druple, and Wordpress.
Web Guy
I build tons of web pages, I still might use Dreamweaver, Druple, or Wordpress. I have been working with libraries and frameworks.
Grunt
I have written some extensions for some frameworks and have started building up my own libraries
Minion (right hand man/women/igor)
I have extensive libraries, and am building my own framework.
Overlord
I have my own framework, and it has been used on several projects.
Neo
I don't believe in frameworks I just believe in me. Coo Coo Ka Choo.
And those looking to hire me I fall in to the Grunt catigory, and am on my way to Minion
Tuesday, June 18, 2013
Live!
I went Live with www.fracturednations.com today. It is live with the release of my first solo Opencart extension Dynamic CSS. Dynamic CSS allows CSS changes without scripting from the admin system.
You can also check out out the demo site to play with the CSS extension.
www.fracturednations.info
You can also check out out the demo site to play with the CSS extension.
www.fracturednations.info
Friday, April 19, 2013
I just wrote this the other day and thought it might be helpful for any one else that is working with google maps. Its an earthquake map the queries the USGS for the latest earthquakes. Check it out.
We show earthquakes that have happened around the world within the last 7 days. This map contains all earthquakes with magnitude greater than 2.5 located by the USGS in the last week.
We show earthquakes that have happened around the world within the last 7 days. This map contains all earthquakes with magnitude greater than 2.5 located by the USGS in the last week.
Joseph Tveter - Fractured Nations
Thursday, January 17, 2013
Embed Flash with PHP.
Its been a while. I figured I should put something up. Here is a class I wrote to put Flash on a page with PHP. Enjoy.
<?php
/**
* Description of flash
* @author Joseph Tveter
*
* This will build the object to embed a swf in.
*/
include_once 'view/html/HTML.php';
class flash {
private $embedAttrs = array(
"src" => "flash_obj.swf",
"quality" => "high",
"bgcolor" => "#ffffff",
"width" => "1024",
"height" => "600",
"name" => "flash_obj",
"align" => "middle",
"allowScriptAccess" => "sameDomain",
"allowFullScreen" => "false",
"type" => "application/x-shockwave-flash",
"pluginspage" => "http://www.adobe.com/go/getflashplayer",
"vspace" => "",
"hspace" => "",
"class" => "",
"title" => "",
"accesskey" => "",
"tabindex" => "",
"flashvars" => "",
);
private $params = array(
"allowScriptAccess" => "sameDomain",
"allowFullScreen" => "false",
"movie" => "lobby.swf",
"quality" => "high",
"bgcolor" => "#ffffff",
);
private $objAttrs = array(
"classid" => "clsid:d27cdb6e-ae6d-11cf-96b8-444553540042",
"codebase" => "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0",
"width" => "1024",
"height" => "600",
"id" => "flash_obj",
"align" => "middle",
"onafterupdate" => "",
"onbeforeupdate" => "",
"onblur" => "",
"oncellchange" => "",
"onclick" => "",
"ondblclick" => "",
"ondrag" => "",
"ondragend" => "",
"ondragenter" => "",
"ondragleave" => "",
"ondragover" => "",
"ondrop" => "",
"onfinish" => "",
"onfocus" => "",
"onhelp" => "",
"onmousedown" => "",
"onmouseup" => "",
"onmouseover" => "",
"onmousemove" => "",
"onmouseout" => "",
"onkeypress" => "",
"onkeydown" => "",
"onkeyup" => "",
"onload" => "",
"onlosecapture" => "",
"onpropertychange" => "",
"onreadystatechange" => "",
"onrowsdelete" => "",
"onrowenter" => "",
"onrowexit" => "",
"onrowsinserted" => "",
"onstart" => "",
"onscroll" => "",
"onbeforeeditfocus" => "",
"onactivate" => "",
"onbeforedeactivate" => "",
"ondeactivate" => "",
"type" => "",
"vspace" => "",
"hspace" => "",
"class" => "",
"title" => "",
"accesskey" => "",
"name" => "",
"tabindex" => "",
"devicefont" => "",
"flashvars" => "",
);
public function __construct($args) {
foreach($args as $k => $v){
foreach($this->embedAttrs as $key => $val){
if($k == $key){
$this->embedAttrs[$k] = $v;
}
}
foreach($this->params as $key => $val){
if($k == $key){
$this->params[$k] = $v;
}
}
foreach($this->objAttrs as $key => $val){
if($k == $key){
$this->objAttrs[$k] = $v;
}
}
}
}
public function draw(){
$html = new HTML("object");
foreach($this->objAttrs as $k => $v){
if($v != ""){
$html->addValue($k, $v);
}
}
foreach($this->params as $k => $v){
if($v != ""){
$pram = new HTML("param");
$pram->addValue("name", $k);
$pram->addValue("value", $v);
$html->addChild($pram);
}
}
$embed = new html("embed");
foreach($this->embedAttrs as $k => $v){
if($v != ""){
$embed->addValue($k, $v);
}
}
$html->addChild($embed);
return $html;
}
}
?>
<?php
/**
* Description of flash
* @author Joseph Tveter
*
* This will build the object to embed a swf in.
*/
include_once 'view/html/HTML.php';
class flash {
private $embedAttrs = array(
"src" => "flash_obj.swf",
"quality" => "high",
"bgcolor" => "#ffffff",
"width" => "1024",
"height" => "600",
"name" => "flash_obj",
"align" => "middle",
"allowScriptAccess" => "sameDomain",
"allowFullScreen" => "false",
"type" => "application/x-shockwave-flash",
"pluginspage" => "http://www.adobe.com/go/getflashplayer",
"vspace" => "",
"hspace" => "",
"class" => "",
"title" => "",
"accesskey" => "",
"tabindex" => "",
"flashvars" => "",
);
private $params = array(
"allowScriptAccess" => "sameDomain",
"allowFullScreen" => "false",
"movie" => "lobby.swf",
"quality" => "high",
"bgcolor" => "#ffffff",
);
private $objAttrs = array(
"classid" => "clsid:d27cdb6e-ae6d-11cf-96b8-444553540042",
"codebase" => "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0",
"width" => "1024",
"height" => "600",
"id" => "flash_obj",
"align" => "middle",
"onafterupdate" => "",
"onbeforeupdate" => "",
"onblur" => "",
"oncellchange" => "",
"onclick" => "",
"ondblclick" => "",
"ondrag" => "",
"ondragend" => "",
"ondragenter" => "",
"ondragleave" => "",
"ondragover" => "",
"ondrop" => "",
"onfinish" => "",
"onfocus" => "",
"onhelp" => "",
"onmousedown" => "",
"onmouseup" => "",
"onmouseover" => "",
"onmousemove" => "",
"onmouseout" => "",
"onkeypress" => "",
"onkeydown" => "",
"onkeyup" => "",
"onload" => "",
"onlosecapture" => "",
"onpropertychange" => "",
"onreadystatechange" => "",
"onrowsdelete" => "",
"onrowenter" => "",
"onrowexit" => "",
"onrowsinserted" => "",
"onstart" => "",
"onscroll" => "",
"onbeforeeditfocus" => "",
"onactivate" => "",
"onbeforedeactivate" => "",
"ondeactivate" => "",
"type" => "",
"vspace" => "",
"hspace" => "",
"class" => "",
"title" => "",
"accesskey" => "",
"name" => "",
"tabindex" => "",
"devicefont" => "",
"flashvars" => "",
);
public function __construct($args) {
foreach($args as $k => $v){
foreach($this->embedAttrs as $key => $val){
if($k == $key){
$this->embedAttrs[$k] = $v;
}
}
foreach($this->params as $key => $val){
if($k == $key){
$this->params[$k] = $v;
}
}
foreach($this->objAttrs as $key => $val){
if($k == $key){
$this->objAttrs[$k] = $v;
}
}
}
}
public function draw(){
$html = new HTML("object");
foreach($this->objAttrs as $k => $v){
if($v != ""){
$html->addValue($k, $v);
}
}
foreach($this->params as $k => $v){
if($v != ""){
$pram = new HTML("param");
$pram->addValue("name", $k);
$pram->addValue("value", $v);
$html->addChild($pram);
}
}
$embed = new html("embed");
foreach($this->embedAttrs as $k => $v){
if($v != ""){
$embed->addValue($k, $v);
}
}
$html->addChild($embed);
return $html;
}
}
?>
Wednesday, October 31, 2012
I felt inspired to go back to my animation roots for an evening.
When I heard that Disney is reacquiring the Star Wars Franchise I felt inspired to edit the Imperial March to Steamboat Wilie. Enjoy.
http://www.youtube.com/watch?v=xdqH85LSuGE
http://www.youtube.com/watch?v=xdqH85LSuGE
Wednesday, October 24, 2012
Web Page Update
Updated the Fractured Nations page. I now have a timeline till go live.
www.fracturednations.com
www.fracturednations.com
Tuesday, October 16, 2012
E-mail attachments with php
So the boss wanted to get a bunch of stats out of the database on a daily basis. Our server guy has been doing it for her, and he complains that it takes time, which it does. And he does not pull all the data she wants because some of it needs to be cleaned before it will display nicely. So I figured it would be better done with a php script set to execute in a daily CRON. I got put to this because she really wanted the data that was dirty. I could see my way threw the project but I had to figure out one or two things. The main being how do you sent an email with an attachment with code. So the next few posts will be addressing e-mailing with code, and data cleaning.
Monday, September 17, 2012
Weird Dream Last Night
So my wife and I have been looking at house plans with the intent of building one day. And I have been scripting a lot. I don't know exactly what triggered it but I had a dream we were building the house and I was laying out the floor with CSS and Javascript. I made it self cleaning. To bad it can't really be done this way.
<div id="kitchenFloor" class="Pergo Mahogany WideStrips" onwalk="selfClean()"></div>
function selfClean()
{
var floor = house.getElementById("kitchenFloor");
if(floor.mud == true)
{
//remove Mud
floor.mud = false;
}
}
<div id="kitchenFloor" class="Pergo Mahogany WideStrips" onwalk="selfClean()"></div>
function selfClean()
{
var floor = house.getElementById("kitchenFloor");
if(floor.mud == true)
{
//remove Mud
floor.mud = false;
}
}
Tuesday, September 11, 2012
HTML form element class object in PHP
Form Elements as easy as
$elem = new FormElement("yourElement", "Hello World Element");
echo $elem->HTML();
This Will print
--------------------------
<div class=''>Hello World Element</div>
<input id="yourElement" name="yourElement" type="text" form="form" onblur="Validate('yourElement')"/>
<div name='err' class='error'></div>
--------------------------
The last div named 'err' can be used to display errors from the validation.
<?php
/**
* Description of FormElement
* Form Element HTML Object
* @author Joseph Tveter
*
* $name is the name and id of the form element.
* $cmd is the HTML tag
* $label is the Label the User will see for the field the default is that it will not be there.
* $pos is the position of the label. The default is "top", but it will also accept "right", "left", and "bottom"
* $formName is the name of the form the element is attached to. The default is "form"
* $type is the type of input tag it is. The default is "text"
* $onblur is the javascript function called onblur. default will call the function called "Validate" with the name of the field. false will not include this field.
* $val is the value the tag has or will return. The default is ""
* $req is weather to make the field required or not. The default is false
* $disabled is weather to make the field disabled or not. The default is false
* $size is the size of the input field. The default is ""
* $maxLength is the Maximum Length of the input field. The default is ""
* $fullclass is the class assigned to the div wrapper around the label and form element. The default is ""
* $titleClass is the class assigned to the label. The default is ""
* $elementClass is the class of the form element. The default is ""
*/
class FormElement extends HTML
{
public function __construct($name, $label = "", $cmd = "input", $pos = "top", $formName = "form", $type = "text", $onblur = "default", $val = "", $req = false, $disabled = false, $size = "", $maxLength = "", $elementClass = "", $fullclass = "", $titleClass = "")
{
parent::__construct("div");
if($fullclass != "")
{
parent::addValue("class", $fullclass);
}
$input = new HTML($cmd);
$input->addValue("id", $name);
$input->addValue("name", $name);
$input->addValue("type", $type);
$input->addValue("form", $formName);
if($onblur != "default")
{
if($onblur != false)
{
$input->addValue("onblur", $onblur);
}
}
else
{
$input->addValue("onblur", "Validate('$name')");
}
if($val != "")
{
$input->addValue('value', $val);
}
if($disabled == true)
{
$input->addValue('disabled', "disabled");
}
if($req == true)
{
$input->addValue("required", "required");
}
if($size != "")
{
$input->addValue("size", $size);
}
if($maxLength != "")
{
$input->addValue("maxlength", $maxLength);
}
if($elementClass != "")
{
$input->addValue("class", $elementClass);
}
if($label != "")
{
switch($pos)
{
case "":
parent::addChild("<div class='$titleClass'>$label</div>");
parent::addChild($input->HTML());
parent::addChild("<div name='err' class='error'></div>");
break;
case "top":
parent::addChild("<div class='$titleClass'>$label</div>");
parent::addChild($input->HTML());
parent::addChild("<div name='err' class='error'></div>");
break;
case "bottom":
parent::addChild($input->HTML());
parent::addChild("<div class='$titleClass'>$label</div>");
parent::addChild("<div name='err' class='error'></div>");
break;
case "right":
$input->addChild("<span class='$titleClass'>$label</span>");
parent::addChild($input->HTML());
parent::addChild("<div name='err' class='error'></div>");
break;
case "left":
parent::addChild("<label for='$name' class='$titleClass'>$label</label>");
parent::addChild($input->HTML());
parent::addChild("<div name='err' class='error'></div>");
break;
}
}
else
{
parent::addChild($input->HTML());
}
}
}
?>
$elem = new FormElement("yourElement", "Hello World Element");
echo $elem->HTML();
This Will print
--------------------------
<div class=''>Hello World Element</div>
<input id="yourElement" name="yourElement" type="text" form="form" onblur="Validate('yourElement')"/>
<div name='err' class='error'></div>
--------------------------
The last div named 'err' can be used to display errors from the validation.
<?php
/**
* Description of FormElement
* Form Element HTML Object
* @author Joseph Tveter
*
* $name is the name and id of the form element.
* $cmd is the HTML tag
* $label is the Label the User will see for the field the default is that it will not be there.
* $pos is the position of the label. The default is "top", but it will also accept "right", "left", and "bottom"
* $formName is the name of the form the element is attached to. The default is "form"
* $type is the type of input tag it is. The default is "text"
* $onblur is the javascript function called onblur. default will call the function called "Validate" with the name of the field. false will not include this field.
* $val is the value the tag has or will return. The default is ""
* $req is weather to make the field required or not. The default is false
* $disabled is weather to make the field disabled or not. The default is false
* $size is the size of the input field. The default is ""
* $maxLength is the Maximum Length of the input field. The default is ""
* $fullclass is the class assigned to the div wrapper around the label and form element. The default is ""
* $titleClass is the class assigned to the label. The default is ""
* $elementClass is the class of the form element. The default is ""
*/
class FormElement extends HTML
{
public function __construct($name, $label = "", $cmd = "input", $pos = "top", $formName = "form", $type = "text", $onblur = "default", $val = "", $req = false, $disabled = false, $size = "", $maxLength = "", $elementClass = "", $fullclass = "", $titleClass = "")
{
parent::__construct("div");
if($fullclass != "")
{
parent::addValue("class", $fullclass);
}
$input = new HTML($cmd);
$input->addValue("id", $name);
$input->addValue("name", $name);
$input->addValue("type", $type);
$input->addValue("form", $formName);
if($onblur != "default")
{
if($onblur != false)
{
$input->addValue("onblur", $onblur);
}
}
else
{
$input->addValue("onblur", "Validate('$name')");
}
if($val != "")
{
$input->addValue('value', $val);
}
if($disabled == true)
{
$input->addValue('disabled', "disabled");
}
if($req == true)
{
$input->addValue("required", "required");
}
if($size != "")
{
$input->addValue("size", $size);
}
if($maxLength != "")
{
$input->addValue("maxlength", $maxLength);
}
if($elementClass != "")
{
$input->addValue("class", $elementClass);
}
if($label != "")
{
switch($pos)
{
case "":
parent::addChild("<div class='$titleClass'>$label</div>");
parent::addChild($input->HTML());
parent::addChild("<div name='err' class='error'></div>");
break;
case "top":
parent::addChild("<div class='$titleClass'>$label</div>");
parent::addChild($input->HTML());
parent::addChild("<div name='err' class='error'></div>");
break;
case "bottom":
parent::addChild($input->HTML());
parent::addChild("<div class='$titleClass'>$label</div>");
parent::addChild("<div name='err' class='error'></div>");
break;
case "right":
$input->addChild("<span class='$titleClass'>$label</span>");
parent::addChild($input->HTML());
parent::addChild("<div name='err' class='error'></div>");
break;
case "left":
parent::addChild("<label for='$name' class='$titleClass'>$label</label>");
parent::addChild($input->HTML());
parent::addChild("<div name='err' class='error'></div>");
break;
}
}
else
{
parent::addChild($input->HTML());
}
}
}
?>
HTML Form Class Object
I got your form right here.
$form = new form("myform");
echo $form->HTML();
This will print
----------------------
<form id="myform" name="myform" action="index.php" method="post">
</form>
---------------------
<?php
/**
* Description of form
* HTML form Object
* @author Joseph Tveter
*/
class form extends HTML
{
public function __construct($name = "form", $action = "index.php", $method = "post")
{
parent::__construct("form");
parent::addValue("id", $name);
parent::addValue("name", $name);
parent::addValue("action", $action);
parent::addValue("method", $method);
}
}
?>
Subscribe to:
Posts (Atom)