i have wrote some html and php
my form doesnt work so fine i cant find my error
if somebody doesnt mind here is the code.

Recommended Answers

All 7 Replies

<?php
if (isset ($_POST['contact_name']) && isset ($_POST['contact_email']) && isset ($_POST['contact_text'])){

@$contact_name = $_POST['contact_name'];
@$contact_email = $_POST['contact_email'];
@$contact_text = $_POST['contact_text'];

if (!empty($contact_name) && !empty ($contact_email) && !empty ($contact_text)){
echo ("OK.");

} else{
echo "All fields are required.";

}

}

?>
<form action="index.php" method="post">
Name:<br><input type="text" name="contact_email"><br><br>
Email adress:<br><input type="text" name="contact_email"><br><br>
Message:<br>
<textarea name="contact_text" rows="6" cols="30"></textarea><br><br>
<input type="submit" value="Send">
</form>
Member Avatar for Zagga

Hi,

When you say your form doesn't work, what is it 'not' doing that you expect it to?

so in all the 3 fields i wrote a letter and when i click the cend button it must show: OK
but id doesnt show nothing

Member Avatar for Zagga

Check the name of your 'name' form field (line 20).

hey i think this part of the code is wrong

<form action="index.php" method="post">

you must replace it with

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

hi you can also look at this code that i came up using your code with slight modification on it

<?php
if(isset($_POST['submit']))
{

$contact_name = $_POST['contact_name'];
$contact_email = $_POST['contact_email'];
$contact_text = $_POST['contact_text'];

if (!empty($contact_name) && !empty ($contact_email) && !empty ($contact_text)){
echo ("OK.");

} else{
echo "All fields are required.";

}

}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Name:<br><input type="text" name="contact_name"><br><br>
Email adress:<br><input type="text" name="contact_email"><br><br>
Message:<br>
<textarea name="contact_text" rows="6" cols="30"></textarea><br><br>
<input type="submit" value="Send">
</form>

not been tested if it really work but you can always find it out:D

hi nevermind my first post i think this is what your looking for

<?php



$contact_name = $_POST['contact_name'];
$contact_email = $_POST['contact_email'];
$contact_text = $_POST['contact_text'];



if (!empty($contact_name) && !empty ($contact_email) && !empty ($contact_text))
    {
echo "ok";
} else{
echo "All fields are required.";
}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

Name:<br><input type="text" name="contact_name"><br><br>
Email adress:<br><input type="text" name="contact_email"><br><br>
Message:<br>
<textarea name="contact_text" rows="6" cols="30"></textarea><br><br>
<input type="submit" value="send">
</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.