Page 1 of 1

validating problems

Posted: Thu Apr 28, 2005 8:21 am
by ~sikka~
Hi. I have this form here: http://www.notypo.no/kontakt.php that doesnt work properly. I am trying to turn on validation so that two of the fields are restricted. But I don't know how to fix this.

this is my php cut from a file called kt.php:

Code: Select all

<?php

    $myemail = "bestill@notypo.no";

    if (!isset($epost))
    echo "Somebody Goofed $ip" ;

    if(!isset($_POST['submit']))
            {
            
            else
        {
            if(!isset($_POST['navn']) || strlen($_POST['navn']) <= 0)
            {
                echo 'Error: You did not enter your name.<br />';
                exit();
            }
            if(!isset($_POST['epost']) || strlen($_POST['epost']) <= 0)
            {
                echo 'Error: You did not enter your email address.<br />';
                exit();
            }
            
            


    $todayis = date("l, j F, Y, g:i") ;

    $subject = "Henvendelse fra notypo.no - fra kontaktsida" ;

    $message = " $todayis [GST] \n
    Navn: $navn \n
    Adresse: $gateadresse \n
    Poststed: $poststed \n
    Telefon: $telefon \n
    Epost: $epost ($visitormail)\n
    Kommentarer: $kommentarer \n

    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    ";
    $from = "From: $myemail\r\n";

    if ($myemail != "")
    mail($myemail, $subject, $message, $from);

    ?>


and i have coming from the form like this:

<form name="kontakt" id="kontakt" method="post" action="kt.php">

Posted: Thu Apr 28, 2005 9:37 am
by jmrdeuce32
You are telling it to check if the fields are set only if submit is not set.

It should be:

Code: Select all

if(isset($_POST['submit'])){

if(!isset($_POST['navn']) || strlen($_POST['navn']) <= 0){

echo 'Error: You did not enter your name.<br />';
}
etc...