WebSite-PHP Framework PHP
Multi language
Simple Ajax mode
No HTML, no JavaScript
URL rewriting
Mail sending
Sitemap - RSS - Web service
Download WebSite-PHP FrameWork now
 


Loading
 


Tutorial Textbox

Tutorials

>

Tutorial Textbox



Tutorial 1 : Simple TextBox
File: /pages/tutorials/textbox/textbox-01.php

<?php
class Textbox01 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : Simple TextBox";
        
        
$this->render = new TextBox($this);
    }
}
?>


Tutorial 2 : Simple TextBox with default text
File: /pages/tutorials/textbox/textbox-02.php

<?php
class Textbox02 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : Simple TextBox 
                                with default text"
;
        
        
$this->render = new TextBox($this);
        
$this->render->setValue("default text");
    }
}
?>


Tutorial 3 : TextBox with presence live validation
File: /pages/tutorials/textbox/textbox-03.php

<?php
class Textbox03 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : TextBox with presence 
                                live validation"
;
        
        
$form = new Form($this); 
        
        
$edt_text = new TextBox($form);
        
$text_box_validation = new LiveValidation();
        
$text_box_validation->addValidatePresence();
        
$text_box_validation->activeValidationOnInit();
        
$edt_text->setLiveValidation($text_box_validation);
        
        
$form->setContent($edt_text);
        
$this->render $form;
    }
}
?>


Tutorial 4 : TextBox with multi live validation (numeric, mail, presence)
File: /pages/tutorials/textbox/textbox-04.php

<?php
class Textbox04 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : TextBox with multi live 
                            validation (numeric, mail, presence)"
;
        
        
$form = new Form($this); 
        
$table = new Table();
        
        
$edt_numeric = new TextBox($form);
        
$edt_numeric_validation = new LiveValidation();
        
$edt_numeric_validation->addValidatePresence();
        
$edt_numeric_validation->addValidateNumericality();
        
$edt_numeric->setLiveValidation($edt_numeric_validation);
        
        
$table->addRowColumns(new Label("Number :&nbsp;"true)
                                , 
$edt_numeric);
        
        
$edt_mail = new TextBox($form);
        
$edt_mail_validation = new LiveValidation();
        
$edt_mail_validation->addValidatePresence();
        
$edt_mail_validation->addValidateEmail();
        
$edt_mail->setLiveValidation($edt_mail_validation);
        
        
$table->addRowColumns(new Label("Email :&nbsp;"true)
                                , 
$edt_mail);
        
        
$form->setContent($table);
        
$this->render $form;
    }
}
?>


Tutorial 5 : TextBox with onchange javascript event
File: /pages/tutorials/textbox/textbox-05.php

<?php
class Textbox05 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : TextBox with onchange
                                 javascript event"
;
        
        
$this->render = new TextBox($this);
        
$this->render->onChangeJs("alert('change');");
    }
}
?>


Tutorial 6 : TextBox with form, callback method on change
File: /pages/tutorials/textbox/textbox-06.php

<?php
class Textbox06 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : TextBox with form, 
                                callback method on change"
;
        
        
$form = new Form($this);
        
        
$edt_text = new TextBox($form);
        
$edt_text->onChange("onChangeTextBox");
        
$edt_text->setStripTags();
        
        
$form->setContent($edt_text);
        
$this->render $form;
    }
    
    public function 
onChangeTextBox($sender) {
        
$this->addObject(new JavaScript("alert('change');"));
    }
}
?>


Tutorial 7 : TextBox with form, callback method on change in AJAX
File: /pages/tutorials/textbox/textbox-07.php

<?php
class Textbox07 extends Page {
    private 
$edt_text null;
    
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : TextBox with form, 
                        callback method on change in AJAX"
;
        
        
$form = new Form($this);
        
        
$this->edt_text = new TextBox($form);
        
$this->edt_text->onChange("onChangeTextBox");
        
$this->edt_text->setAjaxEvent();
        
$this->edt_text->setStripTags("<b><i>");
        
        
$form->setContent($this->edt_text);
        
$this->render $form;
    }
    
    public function 
onChangeTextBox($sender) {
        
$dialog = new DialogBox("onChangeTextBox"
                    
$this->edt_text->getValue());
        
$this->addObject($dialog);
    }
}
?>


Tutorial 8 : TextBox search with autocomplete
File: /pages/tutorials/textbox/textbox-08.php

<?php
class Textbox08 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : TextBox search 
                                with autocomplete"
;
        
        
// List of values used is available on:
        // http://www.website-php.com/en/tutorials/database/database-05.html
                
        
$form = new Form($this);
                
        
// Create TextBox object
        
$search_text = new TextBox($form);
        
        
// Create AutoCompleteEvent object
        
$autocompete_event = new AutoCompleteEvent($form);
        
$autocompete_event->onSelect("onSelectAutoComplete");
        
$autocompete_event->setAjaxEvent();
        
$autocompete_event->disableAjaxWaitMessage();
        
        
// You can catch the event with JavaScript
        /*$autocompete_event->onSelectJs(
            "if (ui.item.id != '') { alert(ui.item.id); }");*/
        
        // Create AutoComplete object
        
$autocomplete = new AutoComplete(
                        new 
Url("xml/textbox-search.json"), 
                        
1$autocompete_event);

        
// Set autocomplete on the TextBox
        
$search_text->setAutoComplete($autocomplete);
        
$form->setContent($search_text);
        
        
$this->render $form;
    }
    
    public function 
onSelectAutoComplete($sender$id) {
        
$this->addObject(
            new 
DialogBox("onSelectAutoComplete"
                                
"URL: ".$id)
            );
    }
}
?>
File: /pages/xml/textbox-search.php

<?php
class TextboxSearch extends Page {
    public function 
InitializeComponent() {
        
$this->render = new AutoCompleteResult();
        
        
$_GET['term'] = trim(utf8decode(strip_tags($_GET['term'])));
        
$_GET['term'] = addslashes($_GET['term']);
        
        
$sql = new SqlDataView(new FavoritePageDbTable());
        if (isset(
$_GET['filter']) && 
            (
$_GET['filter']==|| $_GET['filter']==0)) {
            
// When there is a filter param used
            
$_GET['filter'] = trim(utf8decode(strip_tags($_GET['filter'])));
            
$_GET['filter'] = addslashes($_GET['filter']);
            if (
$_GET['filter'] == 0) { $_GET['filter'] = " IS NULL"; }
            else { 
$_GET['filter'] = " = 1"; }
            
$sql->setClause(FavoritePageDbTable::FIELD_NAME.
                            
" LIKE '%".$_GET['term']."%' AND ".
                            
FavoritePageDbTable::FIELD_ACTIF.
                            
$_GET['filter']);
        } else { 
// Without filter
            
$sql->setClause(FavoritePageDbTable::FIELD_NAME.
                            
" LIKE '%".$_GET['term']."%'");
        }
        
        
$ind 0;
        
$it $sql->retrieve();
        while (
$it->hasNext()) {
            
$row $it->next();
            
$this->render->add(
                
$row->getValue(FavoritePageDbTable::FIELD_URL), 
                
$row->getValue(FavoritePageDbTable::FIELD_NAME), 
                
$row->getValue(FavoritePageDbTable::FIELD_NAME));
            
$ind++;
        }
        if (
$ind == 0) {
            
$this->render->add(""utf8_encode("No result"), "");
        }
    }
}
?>


Tutorial 9 : TextBox search with autocomplete and dynamic filter
File: /pages/tutorials/textbox/textbox-09.php

<?php
class Textbox09 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : TextBox search 
                    with autocomplete and dynamic filter"
;
        
        
$form = new Form($this);
        
        
// Create ComboBox object (filter)
        // List of actif and inactif is available on:
        // http://www.website-php.com/en/tutorials/database/database-05.html
        // You can modify the list of inactif on:
        // http://www.website-php.com/en/tutorials/database/database-07.html
        
$filter = new ComboBox($form);
        
$filter->addItem(1"ACTIF");
        
$filter->addItem(0"INACTIF");
        
        
// Create TextBox object
        
$search_text = new TextBox($form);
        
        
// Create AutoCompleteEvent object
        
$autocompete_event = new AutoCompleteEvent($form);
        
$autocompete_event->onSelect("onSelectAutoComplete");
        
$autocompete_event->setAjaxEvent();
        
$autocompete_event->disableAjaxWaitMessage();
        
        
// Create AutoComplete object (with filter in the URL)
        
$autocomplete = new AutoComplete(
            new 
Url("xml/textbox-search.json?".
            
"filter='+$('#".$filter->getId()."').val()+'"), 
            
1$autocompete_event);

        
// Refresh URL when change filter
        
$filter->onChangeJS("$('#".$search_text->getId()."').autocomplete(".
            
"'option', 'source', '".$this->getBaseLanguageURL().
            
"xml/textbox-search.json?".
            
"filter='+$('#".$filter->getId()."').val());");
            
        
// Set autocomplete on the TextBox
        
$search_text->setAutoComplete($autocomplete);
        
$form->setContent(new WSPObject($filter$search_text));
        
        
$this->render $form;
    }
    
    public function 
onSelectAutoComplete($sender$id) {
        
$this->addObject(
            new 
DialogBox("onSelectAutoComplete"
                                
"URL: ".$id)
            );
    }
}
?>
File: /pages/xml/textbox-search.php

<?php
class TextboxSearch extends Page {
    public function 
InitializeComponent() {
        
$this->render = new AutoCompleteResult();
        
        
$_GET['term'] = trim(utf8decode(strip_tags($_GET['term'])));
        
$_GET['term'] = addslashes($_GET['term']);
        
        
$sql = new SqlDataView(new FavoritePageDbTable());
        if (isset(
$_GET['filter']) && 
            (
$_GET['filter']==|| $_GET['filter']==0)) {
            
// When there is a filter param used
            
$_GET['filter'] = trim(utf8decode(strip_tags($_GET['filter'])));
            
$_GET['filter'] = addslashes($_GET['filter']);
            if (
$_GET['filter'] == 0) { $_GET['filter'] = " IS NULL"; }
            else { 
$_GET['filter'] = " = 1"; }
            
$sql->setClause(FavoritePageDbTable::FIELD_NAME.
                            
" LIKE '%".$_GET['term']."%' AND ".
                            
FavoritePageDbTable::FIELD_ACTIF.
                            
$_GET['filter']);
        } else { 
// Without filter
            
$sql->setClause(FavoritePageDbTable::FIELD_NAME.
                            
" LIKE '%".$_GET['term']."%'");
        }
        
        
$ind 0;
        
$it $sql->retrieve();
        while (
$it->hasNext()) {
            
$row $it->next();
            
$this->render->add(
                
$row->getValue(FavoritePageDbTable::FIELD_URL), 
                
$row->getValue(FavoritePageDbTable::FIELD_NAME), 
                
$row->getValue(FavoritePageDbTable::FIELD_NAME));
            
$ind++;
        }
        if (
$ind == 0) {
            
$this->render->add(""utf8_encode("No result"), "");
        }
    }
}
?>


Tutorial 10 : TextBox search with autocomplete and Analystics tracking
File: /pages/tutorials/textbox/textbox-10.php

<?php
class Textbox10 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : TextBox search 
                                with autocomplete and Analystics tracking"
;
        
        
// List of values used is available on:
        // http://www.website-php.com/en/tutorials/database/database-05.html
                
        
$form = new Form($this);
        
        
// Create TextBox object
        
$search_text = new TextBox($form);
        
        
// Create AutoComplete object
        
$autocomplete = new AutoComplete(
                        new 
Url("xml/textbox-search.json"), 
                        
1$autocompete_event);
        
        
// To track the autocomplete event on Google Analytics                
        
$autocomplete->setTrackEvent("Tutorial""Textbox10""AutoComplete");
        
$autocomplete->setTrackPageView();
        
        
// Set autocomplete on the TextBox
        
$search_text->setAutoComplete($autocomplete);
        
$form->setContent($search_text);
        
        
$this->render $form;
    }
}
?>


Tutorial 11 : Clearable TextBox (very useful for mobile device)
File: /pages/tutorials/textbox/textbox-11.php

<?php
class Textbox11 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : Clearable TextBox 
                            (very useful for mobile device)"
;
        
        
// Create TextBox object
        
$textbox = new TextBox($this);
        
$textbox->setValue("Clearable TextBox");
        
$textbox->clearable();
        
$textbox->setFocus();
        
        
$this->render $textbox;
    }
}
?>



Share

 


Copyright © 2009-2024 WebSite-PHP Framework PHP
Home Documentation Download Quick start Tutorials Wiki Issue Tracker