PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
foreach ($_POST as $key => $value)
{
if (empty($value))
{
echo '<h2>The form field ' . $key . ' was left blank. Please correct it.</h2>';
}
}
?>
Or something along these lines.
Hi Everah !...what do you mean with "simpler version" ? It's much better version ! Thanks for making the code simpler. This often happens to me, I don't know why....some friends told me that I am a complicated man, maybe that's the problem. I really need to learn a lot how to think in simpler way !':oops:' Or maybe it's a great idea too when some experienced programmers publish a book containing complicated code which could be made simpler, much like Programmer Puzzle Book !...lol...
Thanks again, I should learn much from people like you.
Everahs code still allows submission, when no values are present, I am honestly lost as to why it wouldn't work, it reads very logically, and should work. But its not.
As for Christian's code, it too has the same flaws, it should be working too, but it allows submissions with no values entered at all. I'm sincerely confused as to how we can solve this.
<?php
$name = '';
$title = '';
$article = '';
$validation = 0;
$submit = "<input type=submit value=submit your article name=submit>";
if (isset($_POST['name']))
{
$name = $_POST['name'];
// Depending on what you expect name to be you could regex here
}
/*
Handle the other form fields the same way
validating as needed for the expected content
*/
if (empty($name))
{
echo "Please put your name";
}
else
{
$validation++;
}
if (empty($title))
{
echo "Please post your title";
}
else
{
$validation++;
}
if (empty($article))
{
echo "Please post an article";
}
else
{
$validation++;
}
if ($validation == 3)
{
echo $submit;
}
?>
Well you're too picky, help is provided when you want, so feel free to walk away, sorry i'm so whiney, but to avoid that consider all sides of something before pointing a finger. That will avoid some aungish.
Thanks for the assistance, but still this is not working, I know JAVASCRIPT is what I need to use, but Everah warned me against that, and do trust his opinion more than my sense as far as programmin is concerned.