WebSite-PHP Framework PHP
Multi langues
Mode Ajax simple
Aucun HTML, aucun JavaScript
URL rewrinting
Envoi d'email
Sitemap - RSS - Web service
Télécharger le Framework WebSite-PHP maintenant
 


Loading
 


Tutoriel Textbox

Tutoriels

>

Tutoriel Textbox



Tutoriel 1 : Simple TextBox
Fichier: /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);
    }
}
?>


Tutoriel 2 : Simple TextBox with default text
Fichier: /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");
    }
}
?>


Tutoriel 3 : TextBox with presence live validation
Fichier: /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;
    }
}
?>


Tutoriel 4 : TextBox with multi live validation (numeric, mail, presence)
Fichier: /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;
    }
}
?>


Tutoriel 5 : TextBox with onchange javascript event
Fichier: /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');");
    }
}
?>


Tutoriel 6 : TextBox with form, callback method on change
Fichier: /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');"));
    }
}
?>


Tutoriel 7 : TextBox with form, callback method on change in AJAX
Fichier: /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);
    }
}
?>


Tutoriel 8 : TextBox search with autocomplete
Fichier: /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)
            );
    }
}
?>
Fichier: /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"), "");
        }
    }
}
?>


Tutoriel 9 : TextBox search with autocomplete and dynamic filter
Fichier: /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)
            );
    }
}
?>
Fichier: /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"), "");
        }
    }
}
?>


Tutoriel 10 : TextBox search with autocomplete and Analystics tracking
Fichier: /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;
    }
}
?>


Tutoriel 11 : Clearable TextBox (very useful for mobile device)
Fichier: /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
Accueil Documentation Télécharger Quick start Tutoriels Wiki Issue Tracker