/**
* @author zer0fill, Sun Aug 08 02:34:28 PDT 2004
* @desc Validates required input fields. Returns a preformatted string if there's an error
* @return string|null
* @param array $required (key=name / value=displayed error)
*/
function validate($required)
{
// prep the error message, if any
$message ='';
// setup a loop on each required field than doing it manually line by line
foreach ($required as $key=>$item)
{
// find the missing required fields (javascript disabled on user's end)
if (empty($_POST[$key])) {$message .= $item.', ';}
}
// A missing field was detected
if (!empty($message))
{
// setup the error message and remove the trailing `, `
$message = '<div class="errorMsg">Missing Required Field(s): '.substr($message,0,-2).'</div>';
return $message;
}
}
$required = array( 'office_id'=>'Office'
,'role_id'=>'Role'
,'type_id'=>'Type'
,'title'=>'Title'
,'fname'=>'First Name'
,'lname'=>'Last Name'
);
$errors = validate($required);
if (empty($errors))
{
// save to db
}
else
{
$xoopsTpl->assign('errors',$errors);
}
<div class="errorMsg">Missing Required Field(s): Office, Role, Type, Title, First Name, Last Name</div>
FROM
if (!empty($_POST['email']) && !empty($_POST['title']) && !empty($_POST['address']))
{
// save to db
}
else
{
$errors = array();
if (empty($_POST['email']) {$errors[] = 'Missing Email<br />';}
if (empty($_POST['title']) {$errors[] = 'Missing Title<br />';}
if (empty($_POST['address']) {$errors[] = 'Missing Address<br />';}
$xoopsTpl->assign('errors',$errors);
}
TO
if ($form->validate($_POST)) // or $_GET wherever the data is coming from
{
// save to db
}
else
{
$xoopsTpl->assign('errors',$form->errors());
}
---------------------------------
Personal Settings
---------------------------------
First Name | [[u]¯¯¯¯¯¯¯¯[/u]]
Last Name | [[u]¯¯¯¯¯¯¯¯[/u]]
Street | [[u]¯¯¯¯¯¯¯¯[/u]]
City | [[u]¯¯¯¯¯¯¯¯[/u]]
State | [[u]¯¯¯¯¯¯¯¯[/u]]
Zip | [[u]¯¯¯¯¯¯¯¯[/u]]
---------------------------------
Contact Information <--- another header in the same form
---------------------------------
AIM | [[u]¯¯¯¯¯¯¯¯[/u]]
Email | [[u]¯¯¯¯¯¯¯¯[/u]]
[Submit]
Stewdio wrote:
If it is set to yes, then all template files will be updated "automagicly".
Otherwise, deleting the named template file from /templates_c folder works like a charm.
$phone1_tray= new XoopsFormElementTray('Phone 1');
$phone1_tray->addElement(new XoopsFormText('', "phone1", 35, 100, $_POST['phone1']));
$phone1_tray->addElement(new XoopsFormText('x', "phone1_ext", 15, 100, $_POST['phone1_ext']));