PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Custom Input Mask for a valid URL - Reopened

  1. draney
    Member

    We are getting occasional entries in our custom field input (website URL) that have the http:// but no address. In the earlier thread http://www.gravityhelp.com/forums/topic/custom-input-mask-for-a-valid-url#post-164463 we came up with a function to detect the absence of the http prefix and add it if needed to make it a valid URL and it seems to be working except that now we are getting the occasional prefix only which causes a broken link.

    I would like to determine how that prefix is getting there and prevent it? I would be a little surprised if users entered that much and nothing more.

    Is there a way to modify the earlier function and force the field to be blank if it only contains the http:// prefix?

    Posted 11 years ago on Monday April 22, 2013 | Permalink
  2. Hi, I too am having an issue with validation and the site url, when a user adds sitename.com it is invalid, the http:// prefix is not auto added so if a user does not add the http:// then the url will not be valid and the email cannot be sent.

    Posted 11 years ago on Tuesday April 23, 2013 | Permalink
  3. draney
    Member

    @horne3754sg see the link above. The earlier thread solves that problem.

    Posted 11 years ago on Tuesday April 23, 2013 | Permalink
  4. draney
    Member

    So here is the code I have to check for leading "http://" in custom field

    <?php  if((get_post_meta($post->ID, 'website_link', true))) {
    $websiteLink = get_post_meta($post->ID, 'website_link', true);
    if(substr($websiteLink,0,7) == 'http://'){ ?>
    <p><a href="<?php echo get_post_meta($post->ID, 'website_link', true); ?>">Click to view website &raquo;</a></p>
    <?php } else { ?>
    <p><a href="http://<?php echo get_post_meta($post->ID, 'website_link', true); ?>">Click to view website &raquo;</a></p>
    <?php } } ?>

    Can anyone help me modify this to look for "http://" OR "https://" ?

    If user submits a URL in the format of domainname.com (without a protocol prefix) I want to automatically add a prefix of "http://" so it will be a valid URL and the link will work.

    Posted 10 years ago on Wednesday May 29, 2013 | Permalink
  5. David Peralty

    Something like the following should check the two conditions.

    if(substr($websiteLink,0,7) == 'http://' || substr($websiteLink,0,8) == 'https://'){
    Posted 10 years ago on Wednesday May 29, 2013 | Permalink
  6. draney
    Member

    Looks like that works. Thanks!!

    Posted 10 years ago on Thursday May 30, 2013 | Permalink
  7. David Peralty

    No problem, glad I could help.

    Posted 10 years ago on Thursday May 30, 2013 | Permalink