This text is replaced by the Flash movie.

Posts Tagged ‘ExtJS’

Form Sencha Touch 2.0

August 3rd, 2012
If you are planning to create a simple email form for your mobile site you might find this app helpful and add it to your own application. Assisted by Sencha Architect 2, this form panel uses model to validate the form fields and send data to server side script in my case using PHP.

Setup with Sencha Architect. Sencha Architect Setup

Code for submitting the fields
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
onSubmitContactTap: function(button, e, options) {
        var values = this.getValues();
        var contactData = Ext.create('MyApp.model.ContactForm', {
            fullname: values.fullname,
            email: values.email,
            phone: values.phone,
            inquiry: values.inquiry  
        }),
        errs = contactData.validate(),
        msg = '';
 
        if (!errs.isValid()) {
            errs.each(function (err) {
                msg += Ext.String.capitalize(err.getField()) + " " + err.getMessage() + '<br/>';
            });
            Ext.Msg.alert('ERROR', msg);
        } else {
            Ext.Ajax.request({
                url: 'inquiry.php',
                params: {
                    fullname: values.fullname,
                    gender: values.gender,
                    email: values.email,
                    phone: values.phone,
                    inquiry: values.inquiry 
                },
                method: 'POST',
                success: this.handleSuccess,
                failure: this.handleError
            });
 
        } // if

Testing with Chrome.
Sencha Debug

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
  //The Posts
  $fullname = make_safe($_POST['fullname']);
  $email = make_safe($_POST['email']);
  $gender = make_safe($_POST['gender']);
  $phone = make_safe($_POST['phone']);
  $inquiry = make_safe($_POST['inquiry']);
 
  //Simple escape string for mysql insertion
  function make_safe($variable) {
	$variable= strip_tags($variable); 
	$variable = mysql_real_escape_string(trim($variable));
        return $variable;				
  }
 
echo json_encode(array('fullname' => $fullname,
						'email'   => $email,
						'gender'  => $gender,
						'phone'   => $phone,
						'inquiry' => $inquiry));


Download the code (Sencha Architect 2.0)