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.