Submit error

Author Message

Virgilio Lemos

Thursday 27 August 2009 2:12:57 pm

I'm trying to concatenate the results of two forms into one single text but is not working.
What am I doing wrong? I'm newbie in PHP.

<form action={"/content/search"|ezurl}>
<select name="Estado">
<option>RJ</option>

<select name="Cidade">
<option>Niterói</option>

{$Estado= $_POST["Estado"]}
{$Cidade= $_POST["Cidade"]}
{$SearchText = $Estado . ' ' . $Cidade;}
<input type="hidden" name="SearchText" value="{$SearchText}" />

<input id="searchbutton" class="button" type="submit" value="{'Search'|i18n('design/ezwebin/pagelayout')}" alt="{'Search'|i18n('design/ezwebin/pagelayout')}" />

André R.

Friday 28 August 2009 5:45:38 am

Your mixing template code and php code.
Simply put, you can only use php code in *.php files, and only template code in *.tpl files.

Your code needs to be rewritten to template code as this looks to be inside a template.

It would be something like:

{def $post_search_text = ''}
{if ezhttp_hasvariable( 'Estado', 'post' )}
    {set $post_search_text = ezhttp( 'Estado', 'post' )}
{/if}
{if ezhttp_hasvariable( 'Cidade', 'post' )}
    {set $post_search_text = concat($post_search_text, ' ', ezhttp( 'Cidade', 'post' ))}
{/if}
<input type="hidden" name="SearchText" value="{$post_search_text}" />

See:
http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_operators/data_and_information_extraction/ezhttp_hasvariable
http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_operators/data_and_information_extraction/ezhttp
And for concat( press ctrl+f to find it ):
http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_operators

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Virgilio Lemos

Friday 28 August 2009 2:17:23 pm

André,

Could you please verify if I'm making any other mistake, cause de code is still not working.
The selection is not being passed to EzFind.
Message: Search for " " returned...
Isn't a command like onclick missing?

<form action={"/content/search"|ezurl}>
<select name="Estado">
<option>RJ</option>
<select name="Cidade">
<option>Niterói</option>
< /form>

{def $post_search_text = ''}
{if ezhttp_hasvariable( 'Estado', 'post' )}
{set $post_search_text = ezhttp( 'Estado', 'post' )}
{/if}
{if ezhttp_hasvariable( 'Cidade', 'post' )}
{set $post_search_text = concat($post_search_text, ' ', ezhttp( 'Cidade', 'post' ))}
{/if}
<input type="hidden" name="SearchText" value="{$post_search_text}" />

<input id="searchbutton" class="button" type="submit" value="{'Search'|i18n('design/ezwebin/pagelayout')}" alt="{'Search'|i18n('design/ezwebin/pagelayout')}" />

Vincent Tabary

Friday 28 August 2009 3:29:05 pm

Hi,

That looks good for me.

But if it does not works, your "form" could be the cause.

By default, I believe that the attribute "method" for "form" is "get". In your example, you do not mention it and use "post" in your code.

So try this :

<form action={"/content/search"|ezurl} method="post">
<select name="Estado">
<option>RJ</option>
<select name="Cidade">
<option>Niterói</option>
< /form>

Hope this will help you.

Vinz
http://vincent.tabary.me

Virgilio Lemos

Friday 28 August 2009 11:18:31 pm

Hi, Vincent

I inserterd method="post" in the form but still not working.

Regards

André R.

Saturday 29 August 2009 4:47:15 am

I think there are several mistakes done here.
1. post values won't be set before on the next page, so you'll need to click on the search button one more time if the code even works
2. POST and GET variables is not handled by the cache system in eZ Publish by default, only view parameters ( the ones you see in the url when you for instance paginate, like /Something/(offset)/20 )

So this should be handled by javascript (onclick) like this:

<form action={"/content/search"|ezurl}>
<select name="Estado" id="search-selection-estado">
<option selected="selected">RJ</option>
</select>

<select name="Cidade" id="search-selection-cidade">
<option selected="selected">Niterói</option>
</select>

<input type="hidden" name="SearchText" value="{$SearchText}" id="search-text" />

<input id="searchbutton" class="button" type="submit" value="{'Search'|i18n('design/ezwebin/pagelayout')}" alt="{'Search'|i18n('design/ezwebin/pagelayout')}" onclick="var est = document.getElementById('search-selection-estado'), cid = document.getElementById('search-selection-cidade'), searchTxt = document.getElementById('search-text');searchTxt.value = est.value + ' ' + cid.value;" />
</form>

Not tested, you might have to change 'onclick' to 'onkeydown' or something, don't remember the event order when it comes to onclick vs onsubmit right now.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Virgilio Lemos

Saturday 29 August 2009 7:10:45 am

André,
Now worked fine.
Thank you very much to all of you.

Virgilio Lemos

Monday 31 August 2009 6:21:59 am

André,

Back again,
The test was done only in Firefox and is working ok.

Now I tested in IE and the parameters are not been passing.
I also made a test including one text in the space inserted betwin the parameters, and only the text was passed.

Is there any special code for IE to be applyed in this case?

Regards

André R.

Monday 31 August 2009 8:24:44 am

>> Is there any special code for IE to be applied in this case?

Shouldn't be, but you seem to have to debug ie and modify the code to work there as well.

Try something like this in the bottom of the form, to test if the javascript code works:

<a onclick="var est = document.getElementById('search-selection-estado'), cid = document.getElementById('search-selection-cidade'), searchTxt = document.getElementById('search-text');searchTxt.value = est.value + ' ' + cid.value;" href="JavaScript:void(0);">Test</a>

If it does then its the the event order maybe.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Virgilio Lemos

Tuesday 01 September 2009 12:07:19 pm

The code you provided demonstrated that javascrip is working.
By printing the variables I could verify that for IE all of then was empty.
I inserted "value=" for Select Estado and worked great for both browsers.

Do you know how to define value for an select auto filled like the "Cidade" bellow?

<form name="Options" action={"/content/search"|ezurl}>
<select name=" Estado" id="search-selection-estado" onChange="fillSelectFromArray(this.form.Cidade, ((this.selectedIndex == -1) ? null : cidade[this.selectedIndex-1]));">
<option selected="selected" value="">
<option selected="selected" value= RJ> RJ
</select>
<select name=" Cidade" id="search-selection-cidade">
<option selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
</select>
</form >

OBs. This is not the original code, but has also the same problem.

André R.

Wednesday 02 September 2009 1:12:09 am

Im not sure I can help you here, as I don't fully understand what your doing here:

(this.selectedIndex == -1) ? null : cidade[this.selectedIndex-1]

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Virgilio Lemos

Wednesday 02 September 2009 7:34:13 am

This automaticaly load Cidade(city) options for the selected Estado(State), based on the array and function bellow:

{literal}
<script language="JavaScript">
<!—Begin
cidade = new Array(
new Array(
new Array(""),
new Array("Niteroi"),
new Array("Rio de Janeiro"),
new Array("Marica")
)
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[i] = null; 
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1]; 
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
   }
}
//  End -->
</script>
{/literal}

Virgilio Lemos

Friday 04 September 2009 2:15:07 pm

André,
Can you help me with this problem any way?
What kind of debug do you suggest for IE?
Best Regards,

Virgilio Lemos

Monday 14 September 2009 7:33:26 am

The debug shows a problem with IE to take the input selected from search-selection-cidade using getElementById.

Still working ok for Firefox, but IE can take correcly search-selection-estado but not search-selection-cidade, which given result is always empty.

Do anybody knows how to fix this or another way to concatenate those results getting searchTxt to be submited to Solr backend?

Virgilio Lemos

Tuesday 15 September 2009 10:59:33 am

The array format I was using did not has the value to be loaded in option:

new Array("Niteroi",
 

I change it to :

new Array("Niteroi","Niteroi",
 

Now is working in all Browsers.

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 11:36:33
Script start
Timing: Jan 18 2025 11:36:33
Module start 'layout'
Timing: Jan 18 2025 11:36:33
Module start 'content'
Timing: Jan 18 2025 11:36:34
Module end 'content'
Timing: Jan 18 2025 11:36:34
Script end

Main resources:

Total runtime0.7856 sec
Peak memory usage4,096.0000 KB
Database Queries95

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 588.9219152.6094
Module start 'layout' 0.00770.0033 741.531339.3984
Module start 'content' 0.01110.7728 780.9297762.3672
Module end 'content' 0.78390.0017 1,543.296936.2031
Script end 0.7855  1,579.5000 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.4558160.0002
Check MTime0.00130.1662160.0001
Mysql Total
Database connection0.00190.246410.0019
Mysqli_queries0.658683.8306950.0069
Looping result0.00110.1405930.0000
Template Total0.747995.220.3739
Template load0.00230.291020.0011
Template processing0.745694.904020.3728
Template load and register function0.00010.013210.0001
states
state_id_array0.00100.122210.0010
state_identifier_array0.00240.304720.0012
Override
Cache load0.00230.29341330.0000
Sytem overhead
Fetch class attribute can translate value0.00070.090230.0002
Fetch class attribute name0.00180.2267170.0001
XML
Image XML parsing0.00120.153430.0004
class_abstraction
Instantiating content class attribute0.00010.0124290.0000
General
dbfile0.00100.1307230.0000
String conversion0.00000.000940.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.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
14content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
15content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
18content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
30content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
8content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 87
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs