Please make sure to update to WPML 4.3.6 and check our list of Known Issues before reporting

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 10 replies, has 3 voices.

Last updated by Andrey 4 years, 10 months ago.

Assigned support staff: Andrey.

Author Posts
August 26, 2014 at 4:57 am #457433

Richard

A Code change in 3.1.7.1 breaks wordpress search form.

I am using separate domain names for my other languages (www.snobessentials.cn, and hidden link)

My home URL is at

hidden link

The WordPress URL (siteurl) is

hidden link

After my page load, I can see javascript, changing the action of the form dynamically from:

hidden link

to

hidden link

This is caused by sitepress.js

which does:

icl_home = icl_vars.icl_home;

addLoadEvent(function(){
    var lhid = document.createElement('input');
    lhid.setAttribute('type','hidden');
    lhid.setAttribute('name','lang');
    lhid.setAttribute('value',icl_lang);     
    src = document.getElementById('searchform');   
    if(src){
        src.appendChild(lhid);
        src.action=icl_home; 
    }
});

The icl_home variable comes from sitepress.class.php

from:

function language_url( $code = null )
	{
		global $wpdb;

		if ( is_null( $code ) ) {
			$code = $this->this_lang;
		}

		$abs_home = false;
		if ( $code == $this->get_default_language() && $this->settings[ 'language_negotiation_type' ] == 2 ) {
			$option_value = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'");
			if($option_value){
				$abs_home = $option_value;
			}
		} else {
			remove_filter( 'home_url', array( $this, 'home_url' ), 1 );
			$abs_home = get_home_url();
			add_filter( 'home_url', array( $this, 'home_url' ), 1, 4 );
		}

		if ( $this->settings[ 'language_negotiation_type' ] == 1 || $this->settings[ 'language_negotiation_type' ] == 2 ) {
			$url = trailingslashit( $this->convert_url( $abs_home, $code ) );
		} else {
			$url = $this->convert_url( $abs_home, $code );
		}

		return $url;
	}

You can see in this code, that it is loading the siteurl from the options table.

In my scenario, this is

hidden link

When the search form is executed, I receive a page not found error.

Please fix this ASAP.

In WPML 3.1.6, this code only used the home_url, which worked for me.

function language_url( $code = null )
	{
		if ( is_null( $code ) )
			$code = $this->this_lang;

		remove_filter( 'home_url', array( $this, 'home_url' ), 1 );
		$abshome = get_home_url();
		add_filter( 'home_url', array( $this, 'home_url' ), 1, 4 );

		if ( $this->settings[ 'language_negotiation_type' ] == 1 || $this->settings[ 'language_negotiation_type' ] == 2 ) {
			$url = trailingslashit( $this->convert_url( $abshome, $code ) );
		} else {
			$url = $this->convert_url( $abshome, $code );
		}

		return $url;
	}

Thanks,
Rich

August 26, 2014 at 5:17 am #457439

Richard

My current workaround for this is to rename my search form from id="searchform", which is the standard wordpress convention to

id="searchformHeader".

The javacript, no longer finds the form to screw up the action property. This also means that my form now lacks the hidden language input field that the code is trying to add as well.

My form now works in my default language on my main site (www.snobessentials.com), but the results seem to be only limited to the default language, which I believe the hidden input field is suppose to help do.

When I tested .tw and .cn, they also both seem to return only results for that language, so I'm not sure if the hidden language input field is even needed.

In any case, the wpml code is setting the wrong URL for the searchform action, so I still consider this bug open.

Rich

August 26, 2014 at 6:20 am #457450

Minesh
Supporter

Thank you for contacting WPML support!!

I will pass your ticket to our second tier support, please be patient, wait reply from them.

Soon they will get in touch with you.

August 26, 2014 at 1:29 pm #457793

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+02:00)

Did you try WPML version 3.1.7.2 ? You can download it from the downloads section.

August 28, 2014 at 8:12 am #458978

Richard

I installed 3.1.7.2 and the issue is still there.

I redid my workaround of changing the form id to "searchformHeader".
Rich

August 28, 2014 at 1:01 pm #459288

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+02:00)

Thanks for the information.

I've reported about the issue to the development team and they will work on this. I will update you as soon as we have any results in this.

August 28, 2014 at 2:01 pm #459342

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+02:00)

I would suggest you consider providing me with temporary access (wp-admin and FTP) to your site in order to be of better help.
You will find the needed fields for this below the comment area when you log in to leave your next reply.
The information you will enter is private which means only you and I can see and have access to it.

September 1, 2014 at 7:29 am #460761

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+02:00)

Are you able to change in wp-admin > settings > general siteurl from hidden link to hidden link ?

September 1, 2014 at 10:43 am #460985

Richard

Hi Andrey,

I do not want to change the location of my wordpress files. My configuration is a valid configuration for wordpress as shown here:

http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

I've shown above that this bug was introduced in the new versions of WPML.

WPML should correctly handle this configuration.

Also, it seems a shame that the new code does a database query to get the site_url from the options table. It seems this code is called a lot.

I do not want to give login info to my site. It seems you should be able to replicate this configuration in your testing environments. It is a very common setup to have WP in a different directory than the home url.

Thanks,
Rich

September 2, 2014 at 8:08 am #461685

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+02:00)

Thanks for the information !

I let the development team know. I will back to you when we have some results on this.

January 22, 2015 at 3:57 pm #547356

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+02:00)

The issue is fixed in the latest version of WPML plugin.

I am closing this ticket. In case, you still have this issue, please open a new ticket.

The topic ‘[Closed] WPML 3.1.7.1 breaks Search Form’ is closed to new replies.