Tuesday 18 January 2011 8:39:55 am - 7 replies

Introduction

Hi everyone!

Since I notice that there are quite some posts on this topic, I thought I should share with you how I implemented a form where one field depends on another. I will use the classic example where the user selects a province and then is limited in his choice of choosing a city only to those cities that actually exist in that province.

» Read full blog post

Author Message

Damien Pobel

Tuesday 18 January 2011 11:34:05 am

Hi Henrik,
First, thanks for the contribution, you're right it's a quite common need. But your solution needs some fixes at least for security and performances.
Security issue :
Your eZ JS Core server function is vulnerable to SQL injection because you don't escape parameters. In the eZ Publish API, it should be done with eZDB::escapeString() :

<?php
 
class completeCityFunction extends ezjscServerFunctions
{
    public static function searchCities($args)
    {
        $query = '';
        $db = eZDB::instance(); // & is useless in PHP5
 
        $http = eZHTTPTool::instance();
        $query="select distinct(comune) from comuni
                       where comune like '" . $db->escapeString( trim( $http->getVariable( 'q' ) ) ) . "%'
                       and pid ='" . $db->escapeString( $http->getVariable( 'province' ) ) . "'";
 
        $result = $db->arrayQuery($query);
 
        return $result;
        // var_dump($result);
    }
}

Performances

Your tables miss some indexes. At least, the table comuni misses an index on the fields provincia and pid that could be created with the following SQL query :

CREATE INDEX comuni_provincia_pid ON comuni (pid, comune)

Hope that helps. Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Henrik Gren

Tuesday 18 January 2011 12:43:15 pm

Thanks, Damien.

Remarks much appreciated!

Best Regards

Henrik

Nicolas Pastorino

Wednesday 19 January 2011 1:01:57 am

Excellent insight on integration of external tables !

Thanks for this contribution Henrik !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Tony Wood

Wednesday 26 January 2011 1:35:20 am

Nice article Henrik. We need more great articles like this that will attract more developers to see how great eZ Publish is.

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

Marko Žmak

Wednesday 16 February 2011 7:14:42 am

Henrik, I believe that using a class that extends eZPersistentObject instead of calling a raw sql query, would be a better and more "eZ like" implementation.

But this could also be material for a complete new tutorial...

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Henrik Gren

Monday 21 February 2011 9:21:56 am

"

Henrik, I believe that using a class that extends eZPersistentObject instead of calling a raw sql query, would be a better and more "eZ like" implementation.

But this could also be material for a complete new tutorial...

"

Thank you Marko!

Also I would have much appreciated a walk-through example/tutorial on eZPersistentObject.

Anyone?

:)

Peter Keung

Monday 21 February 2011 9:57:26 am

Thiago wrote a good intro to eZPersistentObject here:

http://share.ez.no/learn/ez-publish/a-quick-and-friendly-introduction-to-ezpersistentobject

http://www.mugo.ca
Mugo Web, eZ Partner in Vancouver, Canada

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 04:26:22
Script start
Timing: Jan 18 2025 04:26:22
Module start 'layout'
Timing: Jan 18 2025 04:26:22
Module start 'content'
Timing: Jan 18 2025 04:26:23
Module end 'content'
Timing: Jan 18 2025 04:26:23
Script end

Main resources:

Total runtime0.2268 sec
Peak memory usage4,096.0000 KB
Database Queries90

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 588.0313152.6406
Module start 'layout' 0.00580.0029 740.671939.4844
Module start 'content' 0.00870.2162 780.1563907.2656
Module end 'content' 0.22500.0018 1,687.421926.3984
Script end 0.2268  1,713.8203 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00381.6934160.0002
Check MTime0.00130.5875160.0001
Mysql Total
Database connection0.00120.521010.0012
Mysqli_queries0.128456.5839900.0014
Looping result0.00110.4850880.0000
Template Total0.195986.420.0980
Template load0.00190.851620.0010
Template processing0.194085.509520.0970
Template load and register function0.00010.059110.0001
states
state_id_array0.00140.612320.0007
state_identifier_array0.00110.463830.0004
Override
Cache load0.00160.7154490.0000
Sytem overhead
Fetch class attribute name0.00140.5959140.0001
Fetch class attribute can translate value0.00070.309160.0001
class_abstraction
Instantiating content class attribute0.00000.0125150.0000
XML
Image XML parsing0.00371.633860.0006
General
dbfile0.00160.7054490.0000
String conversion0.00000.011640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplforum_topic/full.tplextension/community_design/design/suncana/override/templates/forum_topic/full.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 36
 Number of unique templates used: 10

Time used to render debug report: 0.0001 secs