PDA

View Full Version : Error when adding website URL during listing submission.



PGGO
May 8, 2012, 01:58 AM
When I’m trying to add a website URL without "http://", the system gives me an error.
It takes time for users to find out what was the problem.
So, I’m considering this as a Bad User experience.

Please refer to the snapshot in attachment.

Steffen Buschkemper
May 8, 2012, 03:25 AM
Hi Petnax,

check this ->
open the File includes/classes/rlValid.class.php

In Line 266 there is the function getDomain



function getDomain( $url = null, $mode = false )
{
return parse_url($url, PHP_URL_HOST);

// $sign = $mode ? '?' : '+';
// if (preg_match('/^(?:http|https|ftp):\/\/((?:[A-Z0-9][A-Z0-9_-]*)(?:\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?/i', $url, $match))
// {
// return $match[1];
// }
//
// return false;
}


The following code checked the url for http, https and also ftp. But u need only the check for http.




// $sign = $mode ? '?' : '+';
// if (preg_match('/^(?:http|https|ftp):\/\/((?:[A-Z0-9][A-Z0-9_-]*)(?:\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?/i', $url, $match))
// {
// return $match[1];
// }
//
// return false;



Change function getDomain with following code and test it



function getDomain( $url = null, $mode = false )
{
return parse_url($url, PHP_URL_HOST);

$sign = $mode ? '?' : '+';
if (!preg_match('?^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+?i', $url, $match))
{
return $match[1];
}

return false;
}


Now the website Field will check for http://

The only Problem is the message. I found no solution for this. But i think the Flynax Team can help you for this.
The regular message is:

The data you have entered in the "Website" field are incorrect.
It would be better Message:

The data you have entered in the "Website" field are incorrect. Correct input for example http:// www. your-domain. com

This Message is in the phrase key: notice_field_incorrect
But this message is not only for the Website Field. It is better to use a separate phrase for the Website field error. this is a Job for Flynax team... ;)

Best regards
Steffen

PGGO
May 8, 2012, 05:59 AM
Hi Steffen,

Thank you for your suggestion; however, after I added this code, nothing happened.

I hope Flynax will take some action in order to fix this error.

Steffen Buschkemper
May 8, 2012, 06:17 AM
Hi Petnax,

It works for me. There are no problems.

Best regards
Steffen

Mike
May 8, 2012, 06:48 AM
Hi all,

If you want to remove url checking you can just edit the field, open edit field page in AP and you'll see that the field has URL as checking condition.

You can just remove it for the field and it will allow any text.

If it's not what you want and you want script to validate urls with or without www solution in code is below.

<b>For those who want to allow links without leading http:// try changes below.</b>

includes/classes/rlValid.class.php



function isUrl( $url )
{
if( strpos($url, 'http://') === false)
{
$url ='http://'.$url;
}
return (bool)preg_match('/^https?:\/\/[a-z0-9-]{2,63}(?:\.[a-z0-9-]{2,})+(?::[0-9]{0,5})?(?:\/|$)\S*$/', $url);
}



<b>To make different error message for the URL fields make following changes.</b>


open includes/classes/rlCommon.class.php and find function checkDynamicForm

find code in the function which handles text fields with condition:

~340 line



elseif ($fields[$poss]['Condition'])
{
if ( !$this -> rlValid -> $fields[$poss]['Condition']($data[$f2]) )
{
$errors[$step] = str_replace( '{field}', '<span class="field_error">"'.$fields[$poss]['name'].'"</span>', $GLOBALS['lang']['notice_field_incorrect']);
}
}


and change to



elseif ($fields[$poss]['Condition'])
{
if ( !$this -> rlValid -> $fields[$poss]['Condition']($data[$f2]) )
{

if( $fields[$poss]['Condition'] == 'isUrl' )
{
$errors[$step] = str_replace( '{field}', '<span class="field_error">"'.$fields[$poss]['name'].'"</span>', $GLOBALS['lang']['notice_url_field_incorrect']);
}else
{
$errors[$step] = str_replace( '{field}', '<span class="field_error">"'.$fields[$poss]['name'].'"</span>', $GLOBALS['lang']['notice_field_incorrect']);
}
}
}



And through Languages manager add new phrase with key notice_url_field_incorrect with your new error message
Phrase text should be like this

"The data you have entered in the {field} field are incorrect. Correct input for example http://www.your-domain.com/"

PGGO
May 8, 2012, 08:01 AM
Mike:

I added the code (first code) you suggest; however, it does not work.
Getting the same issue, the system does not allow me to add a website URL without “http://”

I want to add "www.mysite.com", but system accept it only as "http://www.mysite.com"

Steffen Buschkemper
May 8, 2012, 08:19 AM
Hi Pentax,

there is an mistake. :D LoL
But i think the url with http:// is a better solution.
Not all urls must have a www. syntax!
Flynax has a problem without www!
But not if you type http://your-domain.de ;)


Best regards
Steffen

PGGO
May 8, 2012, 08:35 AM
The reason why I’m considering this as a bad user experience, because most people prefer to type their own domain name starting with www.mysite.com rather than with http://www.mysite.com

It's not a good idea to serve an error every time someone is trying to add a new listing.

The best solution is to accept both version, with http:// and without.

Mike
May 9, 2012, 04:26 AM
There is mistake! Sorry for that.

getDomain is wrong function for those changes

please roll back changes made to getDomain function and apply them to isUrl function (rlValid class)



function isUrl( $url )
{
if( strpos($url, 'http://') === false)
{
$url ='http://'.$url;
}
return (bool)preg_match('/^https?:\/\/[a-z0-9-]{2,63}(?:\.[a-z0-9-]{2,})+(?::[0-9]{0,5})?(?:\/|$)\S*$/', $url);
}

Steffen Buschkemper
May 12, 2012, 07:52 AM
Hi Petnax,

Forget everything that was written before!
I have a good solution for you.
This solution is at first only for Account details.
There is also the same problem!


But the same solution you can us in add listings, but the input field name is other and must be changed in my script!
Its this part-> $('input[name="-Here you must put in the input fieldname-"]').blur(function()
The easy way to find out the field name is firebug (Firefox). I think the fieldname is -> f[website]. But i am not sure.
Then you can put in the script in templates/*your-template*/tpl/add_listing.tpl after <script type="text/javascript" src="{$smarty.const.RL_LIBS_URL}ckeditor/ckeditor.js"></script>

Open the file in templates/*your-template*/tpl/controllers/profile.tpl
After the follow part ->


<script type="text/javascript" src="{$smarty.const.RL_LIBS_URL}jquery/jquery.qtip.js"></script>
<script type="text/javascript">flynax.qtip();</script>
<script type="text/javascript" src="{$smarty.const.RL_LIBS_URL}jquery/jquery.textareaCounter.js"></script>


Paste the following code below



{literal}
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
$('input[name="account[website]"]').blur(function() {
var input = $(this);
var val = input.val();
if (val && !val.match(/^http([s]?):\/\/.*/)) {
input.val('http://' + val);
}
});
});
//]]>
</script>
{/literal}


And now there are no problems! ;)
You can write without http:// -> "your-domain.de" or www. your-domain.de
The script add automatically the "http://" and there are no Error 404
I think that is what you want.

jQuery Rocks! :cool:

Sorry for my bad english!

Best regards
Steffen

John
July 26, 2012, 05:03 AM
Thanks for great code Steffen,
but we fixed that problem in the Flynax 4.1 a bit in different way, you will see it after release.

John