We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7966
    • 90 Posts
    I try to get an textfield value from ajax call, but can’t get it. Below are the codes

    Code in a panel.js
    ,tbar: [{
                xtype: 'textfield'
                ,name: 'context_key'
                ,id: 'context_key1'
                ,emptyText: ('enter context key')
                ,listeners: {
                   // 'change': {fn:this.search,scope:this}
                }
            },{
                 xtype: 'button',
                 text: 'Generate Codes'
                ,handler: this.generateCodes
                ,scope: this
            }]



    Code in processer php file
    $x1= $scriptProperties['context_key'];
    //OR
    $x2 = $modx->getOption('context_key',$scriptProperties, false);
    //OR
    $x3= $scriptProperties['context_key1'];
    
    


    which none work.

    I am new to php and extjs. I checked some components code, but those seems to be codes used in getting a control’s value.

    Any ideas what might be the problem.

    Thanks

      • 3749
      • 24,544 Posts
      This might do what you want:

      $contextKey= $modx->context->get('key');
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 7966
        • 90 Posts
        Quote from: BobRay at Feb 24, 2011, 08:57 PM

        This might do what you want:

        $contextKey= $modx->context->get('key');


        Thanks Bob.

        I think this is to get the context key value.

        What I try to do is ;

        User enters a value in a textfield value in a component page (which has the "context_key" name field value, but it could be anything)

        and I want to get this value in processer’s php code.



          • 3749
          • 24,544 Posts
          Ah. I would have thought that your $x1 or $x3 would do it. Are you sure neither one works?
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 28215
            • 4,149 Posts
            var value = Ext.getCmp('context_key1').getValue();
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 3749
              • 24,544 Posts
              Quote from: splittingred at Feb 24, 2011, 10:27 PM

              var value = Ext.getCmp('context_key1').getValue();


              Ah, someone who knows what he’s talking about. But isn’t the OP looking for a PHP solution?
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 7966
                • 90 Posts
                Quote from: splittingred at Feb 24, 2011, 10:27 PM

                var value = Ext.getCmp('context_key1').getValue();


                thanks. just found that code. it gives the text field in client side value but how do I get that value in processors server side php file (I mean the php file in core/components/mycomp/processors/mgr/resource/getlist.php)

                do we need to add a code like this to buttons handler function

                this.getStore().setBaseParam(’contextkey’,A1); (where A1 is the textfield value)
                  • 28215
                  • 4,149 Posts
                  If you’re trying to adjust the getlist call for the grid, yes.
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                    • 7966
                    • 90 Posts
                    Quote from: splittingred at Feb 24, 2011, 11:33 PM

                    If you’re trying to adjust the getlist call for the grid, yes.

                    Thanks Shaun.

                    This is a panel which has a textbox and button on it. Button runs a function, which need to use the textbox value. There is no result returned from function.

                    Here is the code
                    mycmp.panel.GenerateCode = function(config) {
                        config = config || {};
                        Ext.apply(config,{
                            id: 'test'
                            ,url: mycmp.config.connector_url
                            ,title: 'Create'
                            ,autoHeight: true
                            
                           ,tbar: [{
                                xtype: 'textfield'
                                ,name: 'contextkey'
                                ,id: 'contextkey1'
                                ,emptyText: ('enter context key')
                                ,listeners: {
                                   // 'change': {fn:this.search,scope:this}
                                  }
                            },{
                                 xtype: 'button',
                                 text: 'Generate Code'
                                ,handler: function(){this.generateCodefunction();}
                                ,scope: this
                            }]
                        });
                        mycmp.panel.GenerateCode.superclass.constructor.call(this,config);
                    };
                    Ext.extend(mycmp.panel.GenerateCode,MODx.Panel,{
                        generateCodefunction: function(tf,nv,ov) {
                            
                           var searchbox = Ext.getCmp('contextkey1');
                           this.getStore().setBaseParam('contextkey',searchbox.getValue());
                           var answer = confirm ("Are you sure to continue");
                           if (answer) {
                              MODx.Ajax.request({
                                url: this.config.url
                                ,params: {
                                    action: 'mgr/resource/generatecode'
                    
                                }
                                ,listeners: {
                                    'success': {fn:function(r) {
                                        MODx.msg.alert('DONE success');
                                        this.refresh();
                                    },scope:this}
                                }
                            });
                            
                           } //if (answer)
                           else {alert('Not choosen');}
                         
                        }
                    
                    });
                    Ext.reg('mycmp-panel-generatecode',mycmp.panel.GenerateCode);
                    
                    
                    



                    When I add a code like this
                    var searchbox = Ext.getCmp('contextkey1');
                    this.getStore().setBaseParam('contextkey',searchbox.getValue()); 
                    


                    it doesn’t work.

                    I have the same code on another tab, which has a panel and a grid control(with a textbox and button on it.). The code works there, and I get the text box value with "$scriptProperties[’textfield’]"

                    May it be that the code works depending on the whether controls are on a panel or on a grid. I don’t know, maybe store object is not defined on panel control.

                      • 28215
                      • 4,149 Posts
                      Make this your function:

                          ,generateCodefunction: function(tf,nv,ov) {
                              MODx.msg.confirm({
                                  title: 'Continue?'
                                  ,text: 'Are you sure you want to continue?'
                                  ,params: {
                                      action: 'mgr/resource/generatecode'
                                      ,contextkey: Ext.getCmp('contextkey1').getValue()
                                  }
                                  ,listeners: {
                                      'success': {fn:function(r) {
                                          MODx.msg.alert('Success','DONE success!');
                                      },scope:this}
                                      ,'cancel': {fn:function(r) {
                                          MODx.msg.alert('Error','Not chosen.');
                                      },scope:this}
                                  }
                              });
                          }
                      


                      And this your tbar code:

                      tbar: [{
                                  xtype: 'textfield'
                                  ,name: 'contextkey'
                                  ,id: 'contextkey1'
                                  ,emptyText: 'enter context key'
                              },{
                                   xtype: 'button',
                                   text: 'Generate Code'
                                  ,handler: this.generateCodefunction
                                  ,scope: this
                              }]

                        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com