Results 1 to 3 of 3

Thread: Want to request different controller

  1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    68

    Default Want to request different controller

    Hi guys.

    I'm making a sign-up module right now.

    As you know, if the user enters the information and it has to do two tasks.

    The first thing is to valid check, if the id is already exists.

    And after that it create the row to the database.

    The problem is, i want to request to a different controller.

    For that, i know that i have to change the url property, but it isn't changing at that moment.

    If i can't change the controller, how should i know if it is after the valid check or before the valid check

    Can you help me with this?

    This is the code

    Code:
    Ext.ns("MyApp");
    
    
    Ext.onReady(function() {
    	Ext.QuickTips.init();
    
    
    	var form = new Ext.FormPanel({
    		url : 'Controllers?controller=Login',
    		frame : false,
    		border : false,
    		buttonAlign : 'center',
    
    
    		method : 'POST',
    		id : 'form',
    		bodyStyle : 'padding:10px 10px 15px 15px;background:#dfe8f6;',
    		y : 0,
    
    
    		width : 300,
    		labelWidth : 150,
    		items : [{
    					xtype : 'textfield',
    					fieldLabel : 'Email',
    
    
    					id : 'userEmail',
    					allowBlank : false,
    					vtype : 'email'
    				}, {
    					xtype : 'textfield',
    					fieldLabel : 'Password',
    					// name : 'passwordSignup',
    					id : 'passwordSignup',
    					allowBlank : false,
    					inputType : 'password',
    					vtype : 'passwordlength'
    				}, {
    
    
    					xtype : 'textfield',
    					fieldLabel : 'Confirm Password',
    					id : 'cpassword',
    
    
    					name : 'cpassword',
    					allowBlank : false,
    					inputType : 'password',
    					vtype : 'password'
    				}],
    		buttons : [{
    			text : 'Register',
    			handler : function() {
    
    
    				var form = Ext.getCmp('form').getForm();
    				if (!form.isValid()) {
    					Ext.Msg.alert('Validation error',
    							'Please enter both email and password');
    					return;
    				}
    				form.submit({
    					success : function() {
    						Ext.Msg.alert('Error',
    								'Account already exists, enter a new email')
    						// location.href = "login.htm";
    					},
    					failure : function() {
    
    
    						// Ext.Msg.alert('Succeed', 'Succeed!')
                                                    //************** here i want to change the url, but it is not working :(
    						url : 'Controllers?controller=Signup', //******************
    						form.submit(
    							{
    							success : function() {
    								Ext.Msg
    										.alert('Error',
    												'Account already exists, enter a new email')
    								// location.href = "login.htm";
    							},
    							failure : function() {
    
    
    								Ext.Msg.alert('Succeed', 'Succeed!')
    							}
    						});
    					}
    				});
    
    
    			}
    
    
    		}]
    		,
    
    
    	});
    
    
    	function onLogin(a) {
    		Ext.getCmp('form')
    		var form = formRegister.getForm();
    		if (!form.isValid()) {
    			Ext.Msg.alert('Validation error',
    					'Please enter both email and password');
    			return;
    		}
    		form.submit({
    			success : function() {
    				location.href = "login.htm";
    			},
    			failure : function() {
    				Ext.Msg
    						.alert('Error',
    								'Login service failed. Please retry after a few minutes.')
    			}
    		});
    	}
    
    
    	var winRegister = new Ext.Window({
    				title : 'Sign-up',
    				layout : 'fit',
    				width : 350,
    				height : 190,
    				x : 0,
    				y : 50,
    				resizable : false,
    				closable : false,
    				items : [form]
    			});
    
    
    	winRegister.show();
    });
    
    
    Ext.apply(Ext.form.VTypes, {
    	emailMask : /[a-z0-9_\.\[email protected]\+]/i,
    	email : function(val, field) {
    
    
    		// var username = Ext.getCmp('email').getValue();
    		if (val.search('@') == -1) { // if there isn't char @
    			Ext.apply(Ext.form.VTypes, {
    						emailText : "Email format : [email protected]"
    						,
    					});
    			return false;
    		} else { // now check for the duplication
    			return true;
    		}
    		/*
    		 * Ext.Ajax.request({ url : 'check_username.php', method : 'POST',
    		 * params : 'username=' + username, success : function(o) { if
    		 * (o.responseText == 0) { setusernamevalidfalse(); } } });
    		 */
    
    
    	},
    
    
    	password : function(val, field) {
    
    
    		return (val == Ext.getCmp('passwordSignup').getValue());
    
    
    	},
    	passwordText : 'Passwords do not match',
    
    
    	passwordlength : function(val) {
    
    
    		if (val.length < 3) {
    			// passwordlengthText : 'Password minimum 5 character'
    			Ext.apply(Ext.form.VTypes, {
    						passwordlengthText : 'Password minimum 5 character'
    					});
    			return false;
    		} else {
    
    
    			return true;
    		}
    	}
    	,
    		// passwordlengthText : 'Password minimum 5 character'
    
    
    	});
    
    
    function setusernamevalidfalse() {
    	Ext.apply(Ext.form.VTypes, {
    				uniqueusername : function(val, field) {
    					var username = Ext.getCmp('regUsername').getValue();
    					Ext.Ajax.request({
    								url : 'check_username.php',
    								method : 'POST',
    								params : 'username=' + username,
    								success : function(o) {
    									if (o.responseText == 0) {
    										setusernamevalidfalse();
    									} else {
    										setusernamevalidtrue();
    									}
    								}
    							});
    					return false;
    				}
    			});
    }
    
    
    function setusernamevalidtrue() {
    	Ext.apply(Ext.form.VTypes, {
    				uniqueusername : function(val, field) {
    					var username = Ext.getCmp('regUsername').getValue();
    					Ext.Ajax.request({
    								url : 'check_username.php',
    								method : 'POST',
    								params : 'username=' + username,
    								success : function(o) {
    									if (o.responseText == 0) {
    										setusernamevalidfalse();
    									} else {
    										setusernamevalidtrue();
    									}
    								}
    							});
    					return true;
    				}
    			});
    }

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410

    Default

    Why not have the server decide what function to call based on what is sent?

    Scott.

  3. #3
    Sencha User
    Join Date
    Jul 2012
    Posts
    68

    Default

    success : function(var) { var.url = "address";}I've realized that i could set the url accessing like this.I don't think this is a good way, but anyway it works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •