FairyBusiness
asked on
How to call my form by a name in php?
Hi, I was checking to see whether or not a form as a certain name (because then it should have extra validation) and it was working! but then I did something and now its not! If you click create:
http://auroriella.com/new_product.php
you will see it only displays three fields that are missing values when it should display all of them.
I tested this and it worked before. . .
I guess I changed something because now its back to only display an error message for the text fields. Can someone tell me whats going on?
http://auroriella.com/new_product.php
you will see it only displays three fields that are missing values when it should display all of them.
I tested this and it worked before. . .
function validate_fields() {
global $errors;
if(isset($_POST['submit'])) {
$errors = array();
// Form Validation
$required_fields = array();
foreach($_POST as $key => $value){
$required_fields[] = $key;
}
foreach($required_fields as $fieldname) { // Checks if there was input
if(!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_numeric($_POST[$fieldname]))) {
// Errors occurred
$errors[] = $fieldname;
display_errors();
}
}
if(isset($_POST['products'])) {
echo "hello";
// set required fields here
$required_fields = array("metal_id","featured","stock","materials");
foreach($required_fields as $fieldname) { // Checks if there was input
if(!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_numeric($_POST[$fieldname]))) {
// Errors occurred
$errors[] = $fieldname;
display_errors();
}
}
}
}
}
I guess I changed something because now its back to only display an error message for the text fields. Can someone tell me whats going on?
ASKER
so thats why I put them manually into the array:
It works when I take away the if(isset($_POST['products' ])) {
but then it adds that to all of the other forms in the website and I don't want that. So I named the form products just to target those which deal with products.
if(isset($_POST['products'])) {
echo "hello";
// set required fields here
$required_fields = array("metal_id","featured","stock","materials");
foreach($required_fields as $fieldname) { // Checks if there was input
if(!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_numeric($_POST[$fieldname]))) {
// Errors occurred
$errors[] = $fieldname;
display_errors();
}
}
}
It works when I take away the if(isset($_POST['products'
but then it adds that to all of the other forms in the website and I don't want that. So I named the form products just to target those which deal with products.
Sorry for stupid question, FairyBusiness, but 'products' is the form name or the submit input name?
ASKER
I put it has the form name like this:
<form name="products" enctype="multipart/form-da ta" method="post" action="new_product.php">
<form name="products" enctype="multipart/form-da
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
Glad to help you! This is not the first time I see a your question, but I've never been able to help :-) Bye
ASKER
Oh, well thanks for the help :) I always appreciate it!
Cheers