Web address in edit form

I have a block called Website Url in which the user can input their personal webpage on their profile. What I need to do is to run a check to make sure that the url is in a valid format. I have fouind this:

^(ht|f)tp(s?)://[0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*(:(0-9)*)*(/?)([a-zA-Z0-9-‌.?,'/\+&%$#_]*)?$

but I am not sure if this is correct or how exactly i am supposed to enter this in the check field

caredesign.net
Quote · 18 Feb 2013


return (bool) preg_match('/^(ht|f)tp(s?)://[0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*(:(0-9)*)*(/?)([a-zA-Z0-9-‌.?,'/+&%$#_]*)?$/i', $arg0);

https://www.deanbassett.com
Quote · 18 Feb 2013

thanks deano - i was just about to post this:

return preg_match ('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $arg0);

as the original string did not work - the one above does

BUT - as the field is not a required field, if no url is input, it still will not process form and gives check error

I did your suggestion:

return (bool) preg_match ('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $arg0);

and got same results - it will process the form if a correct url is entered, but not if url field is left blank

caredesign.net
Quote · 18 Feb 2013

I should also mention it is pretty much impossible to match all possible combinations of valid urls. There are just to many.

https://www.deanbassett.com
Quote · 18 Feb 2013

Check to make sure min and max are empty, and yes, you may not be able to do it on a field that is not required as i do not know how to make preg_match accept a empty string as well.



https://www.deanbassett.com
Quote · 18 Feb 2013

well, my next question is this - how can i get the url to show up as a link on the profile page?

caredesign.net
Quote · 18 Feb 2013

you can try this, open file inc/classes/BxDolProfileFields.php and find this code

function getViewableValue( $aItem, $sValue )
    {
        global $site;

        switch( $aItem['Type'] ) {
            case 'text':
            case 'num':
            case 'area':


Added code bellow is bold

function getViewableValue( $aItem, $sValue )
    {
        global $site;

        switch( $aItem['Type'] ) {
            case 'text':
                    switch( $aItem['Name'] ) {
                    case 'Website':
                    return nl2br( '<a href="' . $sValue . '" target="_blank">' . $sValue . '</a>' );
                    default:
                    return $sValue;
                    }
                    break;
         case 'num':

 

-----------------

My new items name
System Name: Website
Caption: _Website
Type: Text

Quote · 18 Feb 2013

thanks a bunch - you have made my day (although i have only been up for 2 hours). Will try now and edit with outcome

EDIT:

Worked beautifully

Idid have to make one small change:

<a href="http://

Reason: If a user inputs a web address of blah-blah.com - then it resolves to mydomain.com/blah-blah.com

caredesign.net
Quote · 18 Feb 2013

I cannot process form with or without  url entered - returns error message.

I did purchase this mod (hack) from market-http://www.boonex.com/m/Profile_Link_Field  but it turns  anything entered in the selected box to a link

example:  enter 7 into the box will return  result of -   http://0.0.0.7/ not very efficient but it is a "Social Profile" Section for adding link to member's facebook,twitter etc... so it does the job  but if you can help resolve the issue with this that would be great

 

 

 

Quote · 19 Feb 2013

what error message are you getting?

is the field set as mandatory?

are the min and max blank?

is there something in the check field?

caredesign.net
Quote · 19 Feb 2013

Yes all fields (min-max) are blank  I entered your

return (bool) preg_match ('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $arg0);

into check field, not mandatory, but doesn't work even when set to mandatory

this comment  does not refer to this  but to the mod I purchased, that is why I would like to try your way instead, as the "mod/hack"  changes any entry into a link -"example: enter 7 into the box will return result of - http://0.0.0.7/ not very efficient but it is a "Social Profile" Section for adding link to member's facebook,twitter etc... so it does the job but if you can help resolve the issue with this that would be great"

The error message I receive is the one I entered into the "Check error message" box - which I now cannot remove even if I have nothing in Check box...

 

 

Quote · 19 Feb 2013

if there is anything in the check field - it automatically makes the field a required field.

Until there is a new way to enter that web address check, you either have to leave it as required or remove the check altogether - i opted to remove the check altogether.

But this creates a question for you mr deanos, would a if then php statement work in that check field - such as

if ((empty($arg0)) {

echo " "; // to make the input a blank space

}

else

{

return preg_match ('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $arg0); // check the url parameters

}

Or something like that. I have not tried this as it just came to me as I was writing this post.

caredesign.net
Quote · 19 Feb 2013

Idk what happened bout it does appear to be working now, (not with field empty) but it would not work by adding

<a href="http:// but it does work without mandatory using  http://site.com  into the field box......  wish you had asked/shared this info before I purchased that mod/hack -  perhaps it may become useful elsewhere.

I added multiple cases for multiple links as it is a box to display other social profiles

switch( $aItem['Type'] ) {
            case 'text':
                 switch( $aItem['Name'] ) {
                    case 'Website':
                    case 'Facebook':
                    case 'Twitter':
                    return nl2br( '<a href="' . $sValue . '" target="_blank">' . $sValue . '</a>' );
                    default:
                    return $sValue;
                    }
                    break;
            case 'num':

SP.gif · 5.9K · 254 views
Quote · 19 Feb 2013

I s it possible to set field to open to the specified case url?  So like

return nl2br( '<a href="' . $sValue . '" target="_blank">' . $sValue . '</a>' );   can somehow b <a href="http://facebook.com/'

twitter/ etc...?  So I make a field called Facebook  can only have link to http://facebook.com/Profile  not  http://somebssitesomewhere.nowhere etc.?

Or set check field to check specific url - not if it's unique but specific to hhtp://facebook.com/....  htttp://twitter.com/...  etc?

Quote · 19 Feb 2013

in my search of google for how to preg_match the url to begin with - I found a variation that checks for domain names host names or whatever else you wanna pull out of the url.

http://www.tutorialchip.com/php/preg_match-examples-7-useful-code-snippets/

check this out - it should get you started in the right direction.

caredesign.net
Quote · 19 Feb 2013

I do not know how to do this but isnt the code you need already in the sites mod it checks the domain is active and then adds active link to the site added ?

 

forgive me if this isnt relevant ..

 

Happy thoughts

Quote · 20 Feb 2013

I'm not that great at figuring out the code as far as where to put what, to even attempt to try this, but  I noticed today that  this "hack"  is also working the same as the mod I purchased, with nothing inthe check field box, it is turning any value added to the box into a link even without entering any http(s):// i  .... a   4, 56 , uy    all turn into an http:// active link to of course a blank page cannot be found type search result

Quote · 20 Feb 2013

Ok so the more I see I am going to stick with the purchased mood as making any block a link by admin option is better than entering the multiple "case" fields into the code, other than that they both have pretty much same functions only the purchased mod/hack requires a little more code editing but is very simple to do.  But I still want to figure out "verify url is "twitter,facebook,plus.google", etc.... 

Quote · 20 Feb 2013

Could it be possible to edit the code so that it would generate a predetermined link so that in the field for "Facebook"

a user could just put their Profile/Page name  and the link would open  http://facebook.com/USERSPROFILE  obviously the red code below does not work but it is an example of what I'd like to do with the code if possible

 

switch( $aItem['Name'] ) {
                    case 'Facebook':
                    return nl2br( '<a href="http://facebook.com/' . $sValue . '" target="_blank">' . $sValue . '</a>' );
                    default:
                    return $sValue;
                    }
                    break;
                  switch( $aItem['Name'] ) {
                    case 'Twitter':
                    return nl2br( '<a href="http://twitter.com/' . $sValue . '" target="_blank">' . $sValue . '</a>' );
                    default:
                    return $sValue;
                    }
                    break;

Quote · 21 Feb 2013

I'm guessing this isn't as "easily" possible to accomplish as I would like...or noone has read this yet....

Quote · 22 Feb 2013

Not tested it, but I guess it should work

switch( $aItem['Type'] ) {
            case 'text':
                  switch( $aItem['Name'] ) {
                case 'Facebook':
                         return nl2br( '<a href="http://facebook.com/' . $sValue . '" target="_blank">' . $sValue . '</a>' );
                case 'Twitter':
                         return nl2br( '<a href="http://twitter.com/' . $sValue . '" target="_blank">' . $sValue . '</a>' );
                default:
              return $sValue;
              }
              break;

Quote · 18 Mar 2013
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.