Hello,

Webforms allow to implement a lot of fields such as email, textfield... but I haven't seen any to implement an URL. Is this possible? how?

Thanks

Comments

quicksketch’s picture

Is there anything special about a URL field other than a little validation? I'd probably suggest using textfield, then use the Additional Validation field to validate that field as a URL. There are a couple examples of how to do custom validation on the Webform project handbook: http://drupal.org/handbook/modules/webform

c-c-m’s picture

Hello,

Thanks for replying.
I have completely rebuilt my site (I have migrated it from phpnuke) and many links will break. I want to make a form so my users can refer to any page whith a broken link so I can repair it. I would like to validate that the provided URL belongs to my domain, that's why I asked.

quicksketch’s picture

Yep, that's a perfect use-case for additional validation then, especially since you need to not only validate the URL, but make sure it comes from a particular domain. If you give your new URL field a form key, of "url", you could use the following code:

if (valid_url($form_values['submitted_tree']['url'], TRUE) && strpos('http://mysite.com') !== FALSE) {
  form_set_error('url', 'The URL you entered is either not valid or doesn't not belong to mysite.com');
}

Open up the "Webform advanced options" and use the code in the "Additional validation" field.

c-c-m’s picture

Thank you very much!

quicksketch’s picture

Oops, I have an equality operator backwards in there. I haven't tested any of this code, but it's along the right idea for sure.

if (!valid_url($form_values['submitted_tree']['url'], TRUE) || strpos('http://mysite.com') === FALSE) {
  form_set_error('url', "The URL you entered is either not valid or doesn't not belong to mysite.com");
}
c-c-m’s picture

Hello,

I may be doing something wrong, I copied-pasted your code into "Webform advanced options" in the "Additional validation" field and replaced "http://mysite.com" with my real domain and it never works. I also deleted ['submitted_tree'] and replaced ['url'] by ['url_del_error'], which is the field's name. It doesn't work neither.

In addition, when editing the Additional validation parameters they are empty, no matter what I wrote. (I am using TinyMCE, but have turned it off when editing this form)

Any help?

Thanks

quicksketch’s picture

Status: Active » Closed (fixed)

Pruning the issue queue. Sorry I'm not able to provide further help on this issue.