Hi,
I want to allow my users to add their website url (if they have one) to their profile on my site. Right now, I have it set up like:
<input type="text" value="http://" />
Couple of problems with this:
1) a user can delete the http:// and type away and then when it is displayed in their profile, the link will not work properly
2) if they enter their website and then go to update it, the update form also has the 'http://' at the start of the value attribute so it appears twice, like http://http://userssite.com
Is there a better way to display the http:// inside of the input box without it being editable? And some what to make certain that the user's website appears as a correct link to their website every time (http:// in front of it, obviously if they enter an incorrect website that is their fault).
Thank you!
Best way to allow users to add their website url
Moderator: General Moderators
-
ninethousandfeet
- Forum Contributor
- Posts: 130
- Joined: Tue Mar 10, 2009 4:56 pm
Re: Best way to allow users to add their website url
You could just check if http://is at the beginning like so:
If you don't want them to type "http://" themselves, just display it as text in front of the box, and then prepend it when you're processing it.
Code: Select all
if(substr($url, 0, 7) == 'http://')//it's valid- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Best way to allow users to add their website url
You could also just str_replace() the http:// away (accept the input with or without it), then as jackpf suggests prepend it when saving/displaying.
Re: Best way to allow users to add their website url
But there could be a valid "http://" somewhere in the query string
I'd go with substr tbh. Or maybe preg_replace, to only replace it at the start of the string.
I'd go with substr tbh. Or maybe preg_replace, to only replace it at the start of the string.
-
ninethousandfeet
- Forum Contributor
- Posts: 130
- Joined: Tue Mar 10, 2009 4:56 pm
Re: Best way to allow users to add their website url
okay, thank you both for the help. i will play around with it and let you know how it turns out.
thank you!
thank you!
Re: Best way to allow users to add their website url
Cool. Good luck.