//VALIDATION
if (isset($_POST['submit'])) {
// initialize an array to hold our errors
$errors = array();
// perform validations on the form data
$required_fields = array('menu_name', 'position', 'visible', 'content');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));
$fields_with_lengths = array('menu_name' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST))
//------- FUNCTIONS ---------
function check_required_fields($required_array) {
$field_errors = array();
foreach($required_array as $fieldname) {
if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) {
$field_errors[] = $fieldname;
}
}
return $field_errors;
}
function check_max_field_lengths($field_length_array) {
$field_errors = array();
foreach($field_length_array as $fieldname => $maxlength ) {
if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $field_errors[] = $fieldname; }
}
return $field_errors;
}
on the validation i cannot understand where parameter "$_POST" is coming from I'm a beginner in php
on the validation i cannot understand where parameter "$_POST" is coming from I'm a beginner in php
$_POST is a supergloabl used by PHP to store POST data. Usually it is used with an HTML form.
So for example, that validation would be true if you had
<form action="myphp.php" method="post">
<input type="submit" name="submit" />
</form>
and then you clicked on the Input button.
$_POST indicates that a form has been submitted to this page with the method="post" (though it could also have been passed through jquery and ajax first) and the if statement is basically checking that the form field (usually the form Submit button) with the name 'submit' has been sent (or posted) through.
So you need to look at the form that is being used to send information through to this page or piece of code (as it could be in the same page) and look for the Submit button and the method in the form opening tag.