For the first part of the problem, I have added a new row (called ‘expiry_reminder’)to the Subscriber table in the database. I also put in a select box on the admin ‘update subsciber’ page. However, I cannot seem to find the correct function which would update the ‘expiry_reminder’ in the database.
Here is the class formSubscriber (i added the expiry_reminder):
class formSubscriber extends form {
/**
* Setup definition
*
*/
public function __construct()
{
$this->action = "/az/admin/index.php?page=" . $_GET["page"];
$this->formID = "formSubscriber";
$this->definition = array(
"id" => array(
"type" => "hidden",
//"value" => getVar('id'),
),
"companyid" => array(
"label" => "Company",
"type" => "select",
"options" => $this->company->getAllSelect(),
//"selected" => getVar('companyid'),
),
"name" => array(
"label" => "Name",
"validationEvents" => array("keyup", "blur"),
"validation" => array(
array("type" => "regexp", "rule" => "[a-z 0-9]{2,128}", "error" => "invalid name"),
),
//"value" => getVar('name'),
),
"email" => array(
"label" => "Email",
"validationEvents" => array("keyup", "blur"),
"validation" => array(
array("type" => "email"),
),
//"value" => getVar('email'),
),
"extra" => array(
"label" => "Extra Subscriber",
"type" => "select",
"class" => "input",
"options" => array("No", "Yes"),
),
"expiry_reminder" => array(
"label" => "Expiry Reminder",
"type" => "select",
"class" => "input",
"options" => array("Yes", "No"),
),
"datetime_added" => array(
"label" => "Subscribe Date",
"type" => "date",
"class" => "input",
"selected" => array(
date("d"),date("m"),date("Y")
),
"style" => array(
"width:50px;margin-right:3px",
"width:100px;margin-right:3px",
"width:80px;margin-right:10px",
"width:50px;margin-right:3px",
"width:50px;margin-right:3px",
"width:50px;margin-right:3px"
),
),
"datetime_expire" => array(
"label" => "Expiry Date",
"type" => "date",
"class" => "input",
"selected" => array(
date("d"),date("m"),date("Y")
),
"style" => array(
"width:50px;margin-right:3px",
"width:100px;margin-right:3px",
"width:80px;margin-right:10px",
"width:50px;margin-right:3px",
"width:50px;margin-right:3px",
"width:50px;margin-right:3px"
),
),
"verifySubmit" => array(
"type" => "submit",
"value" => "Save",
"class" => "submit",
"style" => "margin-left:100px",
),
"reset" => array(
"type" => "reset",
"value" => "Cancel",
"class" => "submit",
"style" => "margin-left:16px",
)
);
}
}
And then here is the section of index.php from the admin files which relates to the ‘subscriber-update’:
case 'subscriber-update':
// check if form validates
$_FORMSUBSCRIBER = new formSubscriber();
if ($_FORMSUBSCRIBER->submitted() && $_FORMSUBSCRIBER->validate($_POST)) {
// update database
$_SUBSCRIBER = new subscriber();
$_SUBSCRIBER->update($_FORMSUBSCRIBER->prepareData($_POST),array("verifySubmit","reset"));
header("Location: /az/admin/subscriber-list/".$_POST['companyid']);
exit;
}
$content = array('subscriber_update.php');
break;
And here is the code from subscriber_update.php:
<?php
//make sure companyid exists
$companyid = array_key_exists("companyid",$_REQUEST) ? $_REQUEST['companyid'] : exit('no company id');
// initiate objects
$_SUBSCRIBER = new subscriber();
$_FORMSUBSCRIBER = new formSubscriber();
// if id exists, get data
if(array_key_exists('subscriberid',$_REQUEST)){
$data = $_SUBSCRIBER->getByID($_REQUEST['subscriberid'],$_REQUEST['companyid']);
$_FORMSUBSCRIBER->setFormValues($data, true);
$h1 = "Edit Subscriber";
}else{
$data = array("companyid"=>$companyid);
$_FORMSUBSCRIBER->setFormValues($data, true);
$h1 = "Add Subscriber";
}
?>
<h1><?= $h1; ?></h1>
<?
$_FORMSUBSCRIBER->outputHTML();
echo $_FORMSUBSCRIBER->defaultJavaScriptSetup();
?>
I cannot see what else I need to modify to enable the expiry_reminder row to be updated.