Page 3 of 4
Posted: Wed Sep 13, 2006 12:04 pm
by christian_phpbeginner
Everah wrote:
How about a little simpler version...
Code: Select all
<?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.
Cheers,
Chris
And I learn from all of you
Posted: Wed Sep 13, 2006 12:59 pm
by akimm
Thanks for the ideas, I'm going to try everah's code and see if that will be enough. Thanks again for the input.
Everahs code
Posted: Wed Sep 13, 2006 1:05 pm
by akimm
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.
Posted: Wed Sep 13, 2006 1:09 pm
by ok
Try JavaScript solution (one similar to mine)
viewtopic.php?p=308918#308918
Posted: Wed Sep 13, 2006 1:12 pm
by akimm
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.
But like they said
Posted: Wed Sep 13, 2006 1:12 pm
by akimm
if java is off on the browser then its all for nothing.
Posted: Wed Sep 13, 2006 1:17 pm
by Luke
that's javascript... not java... there is a difference.
Show us what you tried... those should be working fine.
Posted: Wed Sep 13, 2006 1:19 pm
by akimm
Yes I know. I was looking at that error as you patronized me.
I tried:
Posted: Wed Sep 13, 2006 1:22 pm
by akimm
Code: Select all
<?php
session_start();
$postCollections = array ( 'Name'=>$_POST['name'],
'Email'=>$_POST['email'],
'Title'=>$_POST['title'],
'Article'=>$_POST['article']
);
foreach($postCollections as $key => $value) {
if (empty($value)) {
switch ($key) {
case "Name":
echo "Please put your name".'<br />';
break;
case "Title":
echo "Please post your title".'<br />';
break;
case "Article":
echo "Please post an article".'<br />';
break;
} //end switch statement
} else {
echo $key.': '.$value.'<br />';
}//end if-else
} //end foreach
?>
Everahs code:
Code: Select all
<?php
foreach ($_POST as $key => $value)
{
if (empty($value))
{
echo '<h2>The form field ' . $key . ' was left blank. Please correct it.</h2>';
}
}
?>
Another of Everah's
Code: Select all
<?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;
}
?>
And the code I posted at first, i've tried.
Posted: Wed Sep 13, 2006 1:23 pm
by Luke
man... I was pointing that out to HELP you... I think I'm done helping you... you are too whiney.
Posted: Wed Sep 13, 2006 1:23 pm
by ok
muk.php
Code: Select all
<?php
$submit = 0;
foreach ($_POST as $key => $value)
{
if (empty($value))
{
echo '<h2>The form field ' . $key . ' was left blank. Please correct it.</h2>';
$submit++;
}
}
if($submit > 0)
{
?>
<form method="POST" action="muk.php">
<p><b>Date</b><input type="text" value="<b><?php echo date('F j, Y, g:i a');?></b>" name="date" size="30">
<p><b>Your name</b>
<input type='text' name='name' size='30'></p>
<p><b>Your email</b>
<input type='text' name='email' size='30'></p>
<p><b>article title</b>
<input type='text' name='title' size='30'></p>
<p><b>article</b>
<TEXTAREA NAME='article' COLS='120' ROWS='20' WRAP='virtual'></TEXTAREA></P>
<p><b><input type="submit" value="submit your article" name="submit">
</b></p>
<?php
}else{
?>
Form submitted!
<?php
}
?>
Ok.
Posted: Wed Sep 13, 2006 1:24 pm
by akimm
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.
Posted: Wed Sep 13, 2006 1:26 pm
by Luke
OK... next time I will consider all sides of trying to help you out.

'ok'
Posted: Wed Sep 13, 2006 1:28 pm
by akimm
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.
Ok Ninja
Posted: Wed Sep 13, 2006 1:29 pm
by akimm
Thanks for your cynacism, further proving my point
