acedrummond
Posts: 90
|
Posted: 05/31/2021, 5:05 PM |
|
I built a function and within the function want to place errors via add error i.e.
My code:
function check_phone_fields($which, $ph_num, $ph_type, $ph_text, $ph_carrier)
{
$Container = & CCGetParentContainer($sender);
//No phone number specifed
if ($ph_num == '')
{
if ($ph_type <> 'N')
{
$Container->Errors->addError("No $which Number - Type must be NOT USED used");
}
if ($ph_text <> 'N')
{
$Container->Errors->addError("No $which Number - $which Text must be NOT USED used");
}
if ($ph_carrier <> '')
{
$Container->Errors->addError("No $which Number - $which Carrier must not be NOT USED used");
}
}
// Phone Number is Specified
if ($ph_num <> '')
{
if ($ph_type == 'N')
{
$Container->Errors->addError("$which is present - Phone Type must be SPECIFIED");
}
if ($ph_type == 'C' and $ph_carrier == '')
{
$Container->Errors->addError("$which is Cell - Carrier must be SPECIFIED");
}
if ($ph_type == 'C' and $ph_text == '')
{
$Container->Errors->addError("$which is Cell - Text Option must be SPECIFIED");
}
if ($ph_type == 'L' and $ph_text <> 'N')
{
$Container->Errors->addError("$which is Land Line - Text must be NOT USED");
}
if ($ph_type == 'L' and $ph_carrier <> '')
{
$Container->Errors->addError("$which is Land Line - Carrier must NOT be SPECIFIED");
}
}
return;
}
I get error when I try to execute
Fatal error: Call to a member function addError() on null in C:\wamp64\www\sdc\member_profile_events.php on line 192
This same code when I put it within an event and without it coded in a function works perfectly.
I have to do this function multiple times for different fields in my application and would prefer to re use the code vs. duplicating it.
What am I missing?
_________________
Ace Drummond |
 |
 |
acedrummond
Posts: 90
|
Posted: 06/10/2021, 10:03 AM |
|
Resolved by passing errors back to the calling code and issuing adderror there.
_________________
Ace Drummond |
 |
 |
|