Portal Home > Knowledgebase > Articles Database > HELP ME! HTML form validate URL exists on submit!
HELP ME! HTML form validate URL exists on submit!
Posted by mfwl, 02-07-2011, 02:33 PM |
I have been looking everywhere and I can't sort this!
I have an existing html form asking for a pre-existing subdomain.
I need the subdomain input field to be checked on submission and halted if it does NOT exist!
eg:
User Inputs Subdomain in field of form
Code validates that hxxp://www.domain.com/Subdomain exisits
If it exists the form is sent
If it doesn't the user is asked to enter a valid subdomain!
Please help anyone?
What PHP or javascript should I include to check the validity of a URL on submission of this form like the email validation does!
|
Posted by pmwebster, 02-07-2011, 04:15 PM |
A generic example for cpanel would be something like:
if(is_dir('/home/user/public_html/subdomain'))
{
}
|
Posted by mfwl, 02-07-2011, 06:20 PM |
Thanks I think I have confused things by saying subdomain i meant subfolder..
I am trying to confirm if subfolder exists at http://www.xboxgamertag.com/search/{gamertag}
Because if it does then the gamertag is valid. if the code returns an error then I can assume that the text inputed to the form field is NOT a valid gamertag.
I only want to submit the form if the gamertag entered is valid.
I can also do this by checking if a file exists at
http://avatar.xboxlive.com/avatar/{gamertag}/avatar-body.png
If it does then again the gamertag is valid. if the code returns an error in that the file is not reachable then I can assume that the text inputed to the form field is NOT a valid gamertag.
How can I validate the inputted text in the form field to one of these items??
I can then either pass the form through or tell the user to enter a valid gamertag
Hope you get me!
|
Posted by mfwl, 02-08-2011, 08:58 AM |
I have found a way of this to work...
All I need to do now is replace the word 'gamertag' for the string in my form which is $userlogin
I know its basic but how do I place the string in this argument.
I have tried {$userlogin} .$user_login. 'echo $user_login' and various other things.
I have also tried replacing the whole url 'http://www.xboxgamertag.com/search/gamertag' with a $testurl
and had a $testurl = 'http://www.xboxgamertag.com/search/gamertag' before it but the remoteFileExists argument doesnt like it and keeps returning as valid
Any advice?
|
Posted by mfwl, 02-08-2011, 09:23 AM |
The lower half should be:
$link = "http://www.xboxgamertag.com/search/{$user_login}";
$exists = remoteFileExists($link);
if ($exists) {
echo "Gamertag VALID Please complete form";
} else {
echo "Gamertag INVALID Please check and try again";
}
This works great! Trial and error, hope this helps someone else!
|
Add to Favourites Print this Article
Also Read