942,956 Members | Top Members by Rank

Ad:
Aug 11th, 2010
0

Simple PHP form to Ajax

Expand Post »
Hi Everyone,

I was wondering can someone with Ajax experience to have a look at the following PHP script. Its a simple domain checker.
I am using sessions to pass data from page to page but when I get to this domain checker page and I search for a domain it clears the session.

I was thinking if this form was in ajax it would solve my problem. Unfortunately I know nothing of Ajax and I was wondering would someone be so kind to have a look at it for me?

I hope you can help,
Kind Regards,
Paul


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. function checkDomain($domain,$server,$findText){
  4. // Open a socket connection to the whois server
  5. $con = fsockopen($server, 43);
  6. if (!$con) return false;
  7.  
  8. // Send the requested doman name
  9. fputs($con, $domain."\r\n");
  10.  
  11. // Read and store the server response
  12. $response = ' :';
  13. while(!feof($con)) {
  14. $response .= fgets($con,128);
  15. }
  16.  
  17. // Close the connection
  18. fclose($con);
  19.  
  20. // Check the response stream whether the domain is available
  21. if (strpos($response, $findText)){
  22. return true;
  23. }
  24. else {
  25. return false;
  26. }
  27. }
  28.  
  29. function showDomainResult($domain,$server,$findText){
  30. if (checkDomain($domain,$server,$findText)){
  31. echo "<tr><td>$domain</td><td>AVAILABLE</td></tr>";
  32. }
  33. else echo "<tr><td>$domain</td><td>TAKEN</td></tr>";
  34. }
  35.  
  36. ?>
  37.  
  38.  
  39. <form action="" method="post" name="domain">
  40. Domain name:
  41. <table>
  42. <tr><td><input name="domainname" type="text" /></td></tr>
  43. <tr><td><input type="checkbox" name="com" checked/>.com</td></tr>
  44. <tr><td><input type="checkbox" name="couk" checked/>.co.uk</td></tr>
  45. <tr><td><input type="checkbox" name="net" checked/>.net</td></tr>
  46. <tr><td><input type="submit" name="submitBtn" value="Check domain"/></td></tr>
  47. </table>
  48. </form>
  49. <?php
  50. // The form was submitted
  51. if (isset($_POST['submitBtn'])){
  52. $domainbase = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';
  53. $d_com = (isset($_POST['com'])) ? 'com' : '';
  54. $d_couk = (isset($_POST['couk'])) ? 'couk' : '';
  55. $d_net = (isset($_POST['net'])) ? 'net' : '';
  56.  
  57. // Check domains only if the base name is big enough
  58. if (strlen($domainbase)>2){
  59. echo '<table>';
  60. if ($d_com != '')
  61. showDomainResult($domainbase.".com",'whois.crsnic.net','No match for');
  62. if ($d_couk != '')
  63. showDomainResult($domainbase.".co.uk",'whois.crsnic.net','No match for');
  64. if ($d_net != '')
  65. showDomainResult($domainbase.".net",'whois.crsnic.net','No match for');
  66. echo '</table>';
  67. }
  68. }
  69. ?>
Last edited by Donno24; Aug 11th, 2010 at 1:23 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Donno24 is offline Offline
1 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: redirect to a new page after form validation carried out
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Calling AJAX...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC