Friday, September 25, 2009

html_QuickForm

First of all what is quick form

Introduction quick form..
Please download quikform2 from http://pear.php.net/package/HTML_QuickForm if the QuickForm is not available on C:\xampp\php\PEAR\HTML in my case the drive is C. something other can be in your case, for use that directory you should include that php file in your new script file
require_once 'HTML/QuickForm.php';
$form = new HTML_QuickForm();

I think it's kind of a code of library, in today's days it's important to validation for each kind of web application, like the input value(value submitted by user) should be only number or text, and the input value would be only in the format of email id..on html form.

How it works
In a simple html form there would be different element types like simple text input type, check box, radio button, select type element etc..if we create that html form manually then we should create all that html element by coding manually, but when we use the QuickForm then we don't need to create all that element by manually, we can just create them by calling a particular method(function) and passing relative arguments inside that function..eg:- $form->addElement('text', 'name', 'Item name:', array('size' => 30));
The argument of this function means...A input element item whose type is text, whose name is 'name' and label is 'Item name', and size is 20,
When you call that function it brings the html input box that user can see it on browser and can fill it.
So you don't need to write any html code for make that particular label and input item. You can create different type of element through passing the different values, for example you can pass that arguments for check box type element.
$form->addElement('checkbox', 'contact', 'Please contact me with special offers');

For check box item, these arguments are different than type text input item. so for each input item there would be different arguments, but the function name would be same.

addElement() through this method(function) you can add almost 23 elements,

now I'm telling about another method(function) addRule() through this function you can validate the particular input(eg:- the submitted value by user) example of that function is..
$form->addRule('qty', 'ERROR: Incorrect data type', 'numeric'); -> In these argument the first qty is name of the element and second is the message which can be read by user and third is validation type for example here's the checking if the qty is numeric, if yes then fine otherwise display the error message.

You can add your own validation through adding function like
$form->addRule('email', 'ERROR: Email address already in use on the system', 'callback', 'checkEmail');
as a last argument we are declaring checkEmail statement, now you can create own validation inside your function checkEmail(); Do set the return value is true if the validation is satisfied otherwise set return false

This all validation is happening on server..if you want to do that kind of validation on browser then you can use that arguments in that functions addRule() like...
$form->addRule('pass', 'ERROR: Password missing', 'required', null, 'client'); by this method we are validating the input item on client server(browser); if in your browser the javascript is available then the input validate would be by javascript otherwise in that case the input validate would be on server which is quite interesting I think


setDefaults() -> through that function we can set the default values for form by passing associative arrays, for example
$form->setDefaults(array(
'fname' => 'Enter first name',
'lname' => 'Enter last name',
'sex' => 'female',
'contact' => 1,
'dob' => array('d' => '2', 'M' => '4', 'Y' => '2007'),
'country' => 'zz',
'source' => 'web,ads'
))

In this array the index would be name of element and the value of that array would be the default value for html form.

exportValues()-> through this method(function) return the associative array on which the array of index would be name of particular element and value of array would be submitted value which is submitted by user. eg
$data[fname] => John
$data[lname] => Doe

Alternative way for exportValues() is getSubmitValues(), what is the different between them, getSubmitValues return the all submitted values submitted by user, and the exportValues() return those values only from the elements are exist in form indeed. It’s benefit is no one can hacking your data.

display() through this method you can display the form

Saturday, September 5, 2009

when does the file conflict on svn

When does the file conflict on svn?
If more than one person are changed the same line of particular file for same version, and one of them do commit that new version on svn and other will do update new version for commit then there will be conflict in file.

with example
The same version of project available for everyone, suppose version 5 is available for suman and sanjeev now suppose sanjeev changed line number 8 and 9 of file index.php, and commit that version on svn, now on svn the new version has been made which is 6, now suman also change line number 8 on index.php, now suman try to update new version from svn which is 6, in that time there will be conflict because suman change the same line(code) for version 6, which is already changed by sanjeev..

if suman will change the same line after update new version 6, there will be no conflict because in that time suman will be changing that line for version 7 not for 6 so there will not be any conflict on file.