Page 1 of 1

Embed php code in template

Posted: Thu Feb 17, 2011 10:41 am
by Nettie
Hi all :)

I am not a programmer and I got a php script I have to embed into a site I am working on. I have tried to create a UDT with the php code but couldn't get it working.

The script is supposed to check if a .dk domain name is free or not and post the result on the same page.

The php code:

Code: Select all

<?php
function verify_domain($domain) {
    if (eregi("^[0-9a-z]+([0-9a-z-]+)*(\.dk)$", $domain)) {
        return true;
    } else {
        return false;
    }
}

if (isset($_POST["domain"])) {
    $domain = strtolower($_POST["domain"]);
    $taken = " er desværre <font color=ff0000>optaget</font>. - se registrantinfo her: <a href=http://www.dk-hostmaster.dk/index.php?id=42&query=" . $domain . "&submit.x=31&submit.y=12>" .$domain. "</a>" ;
    $free  = " er <font color=008000>ledigt</font>.";
    $error = " <font color=ff0000>er ikke et gyldigt .dk-domæne.</font>";

    if (verify_domain($domain)) {
        if (checkdnsrr($domain, NS)) {
            echo $domain . $taken;
        } else {
            echo $domain . $free;
        }
    } else {
        echo $domain . $error;
    }
}
?>
The html:

Code: Select all

<form action="index.php" method="post">
<input type="text" name="domain">
</form>
I hope someone can tell me how to get this working as it most likely will not be the last time I will have to embed some php.

Thanks in advance!

Re: Embed php code in template

Posted: Thu Feb 17, 2011 11:29 am
by Jos
Just don't insert the php start- and endtags in your UDT, so delete <?php and ?>

Re: Embed php code in template

Posted: Thu Feb 17, 2011 11:55 am
by Nettie
I tried that but couldn't get it working :(

Re: Embed php code in template

Posted: Thu Feb 17, 2011 12:07 pm
by Jos
Is your UDT inserted in the homepage? If not, you need to change the form action. Maybe <form action="" method="post"> will do

Re: Embed php code in template

Posted: Thu Feb 17, 2011 2:49 pm
by Wishbone
Nettie wrote:I tried that but couldn't get it working :(
What happened when you tried?