Search code examples
phpextjsopenlayerspostgis

passing string in "textfield" to another part in code


I have one question about passing strings from one Ext.formPanel textfield to another part of the code. The thing is that I have two "textfield" in the formPanel and I want the words I enter there as part of the "url" I have in the code. Probably you may ask, why does this guy want that?? this is because the "url" I'm using has a PHP script that generates features stored in a postgis db table as GeoJSON.

This the code:

[CODE]
// define the data source
   var protocol = new OpenLayers.Protocol.HTTP({
   url: "http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom&parameters=" + "column" + ilike '%"string"%',
   format: new OpenLayers.Format.GeoJSON({
        ignoreExtraDims: true,
        'internalProjection': new OpenLayers.Projection("EPSG:900913"),
        'externalProjection': new OpenLayers.Projection("EPSG:4326")
    })
});

formPanel = new GeoExt.form.FormPanel({
    title: "Place Name Search",
    height: 150,
    region: "north",
    protocol: protocol,
    items: [{
        xtype: "textfield",
        id: "column",
        emptyText: "Choose table column",
        fieldLabel: "Choose table column",
        width: 200,
        allowBlank: false
    }, {
        xtype: "textfield",
        id: "string",
        emptyText: "Search inside table",
        fieldLabel: "Enter a word to search",
        width: 200,
        allowBlank: false
    }],
    listeners: {
        actioncomplete: function(form, action) {
            features = action.response.features;
            store.loadData(features);
            vm=map.getLayersByName("Results");
            if(vm.length===0){
                vecLayer = new OpenLayers.Layer.Vector("Results");
                map.addLayer(vecLayer);
                store.bind(vecLayer);
                select.bind(vecLayer);
            }
        }
    },
 buttons: [{text: 'search',
        handler: function(){
            formPanel.search();
        }
    }],
    keys: [{ key: [Ext.EventObject.ENTER],
        handler: function() {
            formPanel.search();
        }
    }]
});
[/CODE]

These are the cases I already tested:

  1. url: http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom: this generates the whole table "boreholes_point_wgs84" as GeoJSON.
  2. url: http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom&parameters=station ilike '%llena%': this generates only one feature, the feature that has "llena" in the "station" column. So, in this way I can find the feature through the search form.

What I was thinking is if I can pass these two strings I enter in "textfield" and modify the "url" in the way that it can catch these two words and form, for example, the second case I put above. I was playing with this:

url: http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom&parameters=" + "column" + ilike '%"string"%', so using the "id" I specified below each xtype, but it doesn't work.

I appreciate any support on this, thanks in advance,

Best regards,

Gery


Solution

  • I'm pretty sure that this solution will help to understand how to solve this problem, I solved myself.