Embed php code in template

General project discussion. NOT for help questions.
Post Reply
User avatar
Nettie
Forum Members
Forum Members
Posts: 53
Joined: Tue Oct 03, 2006 11:42 pm

Embed php code in template

Post 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!
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm

Re: Embed php code in template

Post by Jos »

Just don't insert the php start- and endtags in your UDT, so delete <?php and ?>
User avatar
Nettie
Forum Members
Forum Members
Posts: 53
Joined: Tue Oct 03, 2006 11:42 pm

Re: Embed php code in template

Post by Nettie »

I tried that but couldn't get it working :(
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm

Re: Embed php code in template

Post 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
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Embed php code in template

Post by Wishbone »

Nettie wrote:I tried that but couldn't get it working :(
What happened when you tried?
Post Reply

Return to “General Discussion”