-2

I am working on a domain availability check form, and it is working great. The next thing I want to do is implement this in my website and display the output of the script under the search form. I managed to do this, but the page reloads after submiting the form. How can I stop the reloading and show the output?

I understand it is done by some Jquery, but I can't figure it out how it works.

This is the form

<form action="domaincheck.php" id="domain-searchform">
            <input class="input-text" name="domain" id="s" placeholder="Vul hier je domeinnaam in" type="text" />
                <select class="witch ts-option-search" name="tld">
                          <option value=".be">.be</option><option value=".nl">.nl</option>
                          <option value=".com">.com</option>
                          <option value=".net">.net</option>
                          <option value=".org">.org</option>
                          <option value=".eu">.eu</option>
                          <option value=".uk">.uk</option>
                          <option value=".co.uk">.co.uk</option>
                 </select>
                 <input type="submit" value="Zoek" id="searchsubmit">
         </form>

The result is called at the moment with this

<h3 style="color:#ffffff;font-size:30px; text-align: center">
<?=$result?>
</h3>

And this is the php script to check if the domain is available.

<?php

require_once('Transip/DomainService.php');

if(isset($_GET['domain']) && strlen($_GET['domain']) > 0)
{
    $dom = $_GET['domain'];
    $tld = $_GET['tld'];

    $domain = $dom . $tld;

    try
    {
        $availability = Transip_DomainService::checkAvailability($domain);
        switch($availability)
        {
      //check availability
            case Transip_DomainService::AVAILABILITY_INYOURACCOUNT:
                $result = htmlspecialchars($domain)
                            . ' is not available.';
            break;

            case Transip_DomainService::AVAILABILITY_UNAVAILABLE:
                $result = htmlspecialchars($domain)
                            . ' is not available for transfer.';
            break;

            case Transip_DomainService::AVAILABILITY_FREE:
                $result = htmlspecialchars($domain)
                            . ' is available for registration.';
            break;


            case Transip_DomainService::AVAILABILITY_NOTFREE:
                $result = htmlspecialchars($domain)
                            . ' is registered. If you are the owner,
                                    you could transfer it.';
            break;
        }
    }
    catch(SoapFault $e)
    {
    //error
        $result = 'An error occurred: ' . htmlspecialchars($e->getMessage());
    }
}
else
{
    $domain = '';
    $result = '';
}

?>
Odyssee
  • 2,393
  • 2
  • 19
  • 38
  • 2
    It's called AJAX, google it, there's plenty of guides out there :) – Epodax Nov 26 '15 at 13:12
  • Possible duplicate of [Form submit with AJAX passing form data to PHP without page refresh](http://stackoverflow.com/questions/16616250/form-submit-with-ajax-passing-form-data-to-php-without-page-refresh) – Lucky Chingi Nov 26 '15 at 13:15
  • PHP is server-side. This means that it needs a `request` before it can give a `response`. The only way to do a `request` without reloading is to use `AJAX` – Peter Nov 26 '15 at 13:21

2 Answers2

0

I suggest to have a look at AJAX/PHP (for example the tutorial from W3Schools.

So basically by clicking the submit button you call a JavaScript function which sends a so-called HttpRequest to the server in order to call your PHP script. Then the output of the PHP script is sent back to the browser and you can display the result without reloading the page.

TheRealPetron
  • 31
  • 2
  • 6
0

http://code.tutsplus.com/tutorials/submit-a-form-without-page-refresh-using-jquery--net-59

This tutorial helped me in completing my goal.

I was kind of confused earlier this day about how ajax, jquery and php worked together. I can see the logic now, another lesson learned :)

anyhow, thx for giving some tips!

Odyssee
  • 2,393
  • 2
  • 19
  • 38