hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : HELP ME! HTML form validate URL exists on submit!
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

HELP ME! HTML form validate URL exists on submit!

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-07-2011, 02:33 PM
mfwl mfwl is offline
Junior Guru Wannabe
 
Join Date: Feb 2008
Location: Barnsley, South Yorkshire
Posts: 41
Angry

HELP ME! HTML form validate URL exists on submit!


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!

__________________
Online Hosting and eCommerce solutions with a reliability and price you will like...
Shared / Reseller / Master Reseller Accounts / Web Design / Licensing
Why not come and visit us now @ www.ACE4SPACE.com

Reply With Quote


Sponsored Links
  #2  
Old 02-07-2011, 04:15 PM
pmwebster pmwebster is offline
Junior Guru Wannabe
 
Join Date: May 2010
Location: Kalamazoo, MI
Posts: 38
A generic example for cpanel would be something like:
if(is_dir('/home/user/public_html/subdomain'))
{

}

__________________
::WiredHub::

Reply With Quote
  #3  
Old 02-07-2011, 06:20 PM
mfwl mfwl is offline
Junior Guru Wannabe
 
Join Date: Feb 2008
Location: Barnsley, South Yorkshire
Posts: 41
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!

__________________
Online Hosting and eCommerce solutions with a reliability and price you will like...
Shared / Reseller / Master Reseller Accounts / Web Design / Licensing
Why not come and visit us now @ www.ACE4SPACE.com

Reply With Quote
Sponsored Links
  #4  
Old 02-08-2011, 08:58 AM
mfwl mfwl is offline
Junior Guru Wannabe
 
Join Date: Feb 2008
Location: Barnsley, South Yorkshire
Posts: 41
I have found a way of this to work...

<?php
function remoteFileExists($url) {
$curl = curl_init($url);

//don't fetch the actual page, you only want to check the connection is ok
curl_setopt($curl, CURLOPT_NOBODY, true);

//do request
$result = curl_exec($curl);

$ret = false;

//if request did not fail
if ($result !== false) {
//if request was ok, check response code
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($statusCode == 200) {
$ret = true;
}
}

curl_close($curl);

return $ret;
}
$exists = remoteFileExists('http://www.xboxgamertag.com/search/gamertag');

if ($exists) {
echo 'Gamertag VALID Please complete form';
} else {
echo 'Gamertag INVALID Please check and try again';
}

?>

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?

__________________
Online Hosting and eCommerce solutions with a reliability and price you will like...
Shared / Reseller / Master Reseller Accounts / Web Design / Licensing
Why not come and visit us now @ www.ACE4SPACE.com

Reply With Quote
  #5  
Old 02-08-2011, 09:23 AM
mfwl mfwl is offline
Junior Guru Wannabe
 
Join Date: Feb 2008
Location: Barnsley, South Yorkshire
Posts: 41
* ALL FIXED - Solution!

The lower half should be:

$link = "http://www.xboxgamertag.com/search/{$user_login}";
$exists = remoteFileExists($link);

if ($exists) {
echo "<font color='green'>Gamertag <b>VALID</b> Please complete form</font>";
} else {
echo "<font color='red'>Gamertag <b>INVALID</b> Please check and try again</font>";
}

This works great! Trial and error, hope this helps someone else!

__________________
Online Hosting and eCommerce solutions with a reliability and price you will like...
Shared / Reseller / Master Reseller Accounts / Web Design / Licensing
Why not come and visit us now @ www.ACE4SPACE.com

Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to submit a form from a URL? SmashedPumpkins Programming Discussion 4 02-19-2010 02:07 AM
HTML Form - submit button activation. horizon Programming Discussion 2 01-02-2007 06:17 PM
JavaScript: Turn form submit into URL Zach Highknee Programming Discussion 1 05-15-2005 06:56 PM
Receive HTML Form, Add some then submit to other server yinyang Programming Discussion 3 08-22-2004 11:48 PM
Password submit: .htaccess or html form? astralexis Hosting Security and Technology 4 04-24-2001 01:50 PM

Related posts from TheWhir.com
Title Type Date Posted
Lead Generation Part 1 – Form Fills Blog 2012-11-16 09:03:48
New Jersey Email Voting Raises Security, Legal Questions in US Election Web Hosting News 2012-11-09 09:20:08
The Variable Requirements of Data Center Vendor Selection: Andrew Schaap of Digital Realty Trust Web Hosting News 2011-09-27 15:06:29
Open Source Developer Joomla Releases 1.7 CMS with Enhanced Security Tools Web Hosting News 2011-07-19 18:51:20
Security Researchers Find Phishing Sites on Google Docs Web Hosting News 2011-05-31 14:32:36


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?