I want to save some typing for the user, but it seems we cannot have http:// as the default value, as a url is expected.
Any tips? :)

Comments

petiar’s picture

Version: 6.x-2.x-dev » 6.x-2.9

Subscribing...

jnjn’s picture

Need this aswell asap

wooody’s picture

Hi , if you unchecked the validator then u can insert http:// as a default value.

but if u make it required it will passed, coz there is already value.

tdimg’s picture

Version: 6.x-2.9 » 6.x-2.x-dev

Simply unchecking validation to be able to set http:// as its a default value doesn't do the trick, for two reasons:

1. if it's a required field, the default value is enough to pass through the check and you end up with a link to http://
2. if it's not a required field, and the user doesn't change the field value, then you also end up with a link to http://

But, at least in Drupal 7, you don't have to type http:// to pass validation, www.example.com is good enough. However, there's a usability issue in my opinion in having http:// displayed in the form as a default value or better yet as a placeholder value of the form field.

JCB’s picture

Hi Guys,

I did a really bad hack to get this working.

http:// is added if there is no protocol specified; alternatively the entered protocol is used.

Modify link.inc as shown below:

function _link_process(&$item, $delta = 0, $field, $node) {
  // Trim whitespace from URL.
  $tempurl = trim($item['url']);
  $tempurl = parse_url($tempurl);
  if($tempurl['host'] != ""):
  	$tempurlsuffix = $tempurl['host'];
  elseif($tempurl['path'] != ""):
  	$tempurlsuffix = $tempurl['path'];
  endif;
  if($tempurl['scheme'] != ""):
  	$tempurlprefix = $tempurl['scheme'] . "://";
  elseif($tempurl['scheme'] == ""):
  	$tempurlprefix = "http://";
  endif;  
  $item['url'] = $tempurlprefix . $tempurlsuffix;

  // if no attributes are set then make sure $item['attributes'] is an empty array - this lets $field['attributes'] override it.
  if (empty($item['attributes'])) {
    $item['attributes'] = array();
  }
JCB’s picture

not sure if this helps anybody; however here is the code I now updated on my module in link.inc

function _link_process(&$item, $delta = 0, $field, $node) {
	if($item['url'] != ""):
	$tempurl = trim($item['url']);
	$tempurl = parse_url($tempurl);
	
	if($tempurl['host'] != ""):
		$tempurlsuffix = $tempurl['host'];
	endif;
	
	if($tempurl['path'] != ""):
		$tempurlsuffix = $tempurlsuffix . $tempurl['path'];
	endif;
	
	if($tempurl['scheme'] != ""):
		$tempurlprefix = $tempurl['scheme'] . "://";
	elseif($tempurl['scheme'] == ""):
		$tempurlprefix = "http://";
	endif;
	
	if($tempurl['host'] == "www.facebook.com" || $tempurl['host'] == "www.twitter.com" || $tempurl['host'] == "twitter.com"):
		$tempurlprefix = "https://";
	endif;
	  
	$item['url'] = $tempurlprefix . $tempurlsuffix;
	
	elseif($item['url'] == ""):
		// Trim whitespace from URL.
		$item['url'] = trim($item['url']);
	endif;

  // if no attributes are set then make sure $item['attributes'] is an empty array - this lets $field['attributes'] override it.
  if (empty($item['attributes'])) {
    $item['attributes'] = array();
  }
damienmckenna’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Thank you all for your efforts, but I'm sorry to say that the D6 version is no longer supported.