Get array with field values
You can use the function $form->getFieldValues()
to get an array with all the field values.
Field names are set as array index whereas the field value is set as the corresponding content.
// make sure to validate first :)
if($form->validate()){
// get array with all fields
$data = $form->getFieldValues();
// easly access single fields
$customer_email = $data['customer_email'];
// alternative
$customer_email = $form->getField('customer_email')->getValue();
// ...or loop through the whole array
foreach($data as $field => $value){
echo "The field: $field contains: $value ";
}
}
Uploaded files
For safety reasons, HazzelForms does not copy around the files on your webserver.
When using upload fields, $form->getFieldValues()
will return a multidimensional array containing
the tmp directory and the filename of all uploaded files:
// example
$data = $form->getFieldValues();
// loop through the uploads
foreach($data['uploads'] as $file){
echo $file['dir'] . "is the tmp directory
";
echo $file['name'] . "is the filename";
}
Use the php function move_uploaded_file()
to move a file to a specific directory.
Put this code inside the foreach loop above:
$uploadDir = __DIR__.'/uploads';
$imgPath = $uploadDir.'/'.basename($file['name']);
move_uploaded_file( $file['dir'], $imgPath );