Page 4 of 4
Posted: Wed Sep 13, 2006 1:38 pm
by RobertGonzalez
Okay, stop it, both of you. If we cannot get back on the subject of providing assistance then this thread will have served its purpose and will be locked.
akimm, are you checking for if the form was actually sent? Also, try this to see what is being passed to the $_POST array. Logically, the code I posted should work without incident.
Code: Select all
<?php
foreach ($_POST as $key => $value)
{
echo '<p>The post key is ' . $key . ' and its matching value is ' . $value . '.</p>';
/* if (empty($value))
{
echo '<h2>The form field ' . $key . ' was left blank. Please correct it.</h2>';
}
*/
}?>
Yes
Posted: Wed Sep 13, 2006 1:43 pm
by akimm
Sorry for my biccering.
now, yes the form is definetly sent. I usually post a value into 1 form to make sure its going through.
Everah.
Posted: Wed Sep 13, 2006 1:49 pm
by akimm
Its been a mistake of mine this whole time.
The problem was, I made a file called error.php then included it. However, error.php is seperate from my muk.php which processes the writing of the file to their seperate places.
So please forgive me for this mistake. The code you wrote here, works without error.
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)
{
?>
Thanks for the help.
Posted: Wed Sep 13, 2006 1:49 pm
by akimm
I appreciate it.
Posted: Wed Sep 13, 2006 1:56 pm
by christian_phpbeginner
akimm wrote:but it allows submissions with no values entered at all. I'm sincerely confused as to how we can solve this.
I am refering to the bolded part in the quoted string. PHP is a
server-side scripting language...so, how could you expect PHP to validate your form
without submitting the data first ? If what you want is to
prevent submit after the validation process is completed,
that must be on the client side and use Javascript.
My code and everybody's codes here don't prevent form submissions, but our codes don't
process inputs into the database. Our codes here are for validating and not for processing.
The most important thing is:
- If satisfied conditions are not met, the data should not be INSERTED (PROCESSING) into the database, but you should validate and validate the data until the satisfied conditions are met, then you program PHP to INSERT the satisfied data into the database.
I recommend to use BOTH Javascript and PHP form validation for your solution as quoted from
http://www.zend.com/zend/tut/tutorial-m ... c=0&view=1:
To prevent any kind of intrusion, your best companion is always PHP. Even though you have utilized Javascript, never skip checking data with PHP. This is the most reliable checkpoint before processing input.
And if the user turns off the javascript, your PHP code would still be executed.
Good Luck,
Chris
Everah
Posted: Wed Sep 13, 2006 1:56 pm
by akimm
Do you have any suggestions how I can make sure the data that was filled in stays filled in, rather than being eraced when there is an error.
Re: Everah
Posted: Wed Sep 13, 2006 2:03 pm
by christian_phpbeginner
akimm wrote:Do you have any suggestions how I can make sure the data that was filled in stays filled in, rather than being eraced when there is an error.
Use $_SESSION variables, you should then do like this on muk.php:
Code: Select all
<?php
session_start();
$_SESSION ['name'] = $_POST['name'];
?>
Posted: Wed Sep 13, 2006 2:05 pm
by RobertGonzalez
Set initial vars, then reset them to the passed vars and echo those vars in the form when there is an error. Here is a one-off hint for you...
Code: Select all
<?php
$name = '';
if (isset($_POST['name']))
{
$name = $_POST['name'];
}
?>
<form>
<input type="text" name="name" value="<?php echo $name; ?>" />
Posted: Wed Sep 13, 2006 2:56 pm
by ok
I am glad that I could help!

Posted: Wed Sep 13, 2006 3:04 pm
by RobertGonzalez
ok wrote:I am glad that I could help!

Who did you help?
