I am a bit confused. I have a simple form to add new users, and I damn near have everything working. As a matter of fact it WAS working just fine a few times while testing. I really changed very little. The role "representative" exists yet I still get an error:
<form method="post" action="./">
<label for="firstName">First Name</label>
<input name="firstName" type="text" required>
<label for="lastName">Last Name</label>
<input name="lastName" type="text" required>
<label for="email">Email</label>
<input name="email" type="email" required>
<button name="submit" type="submit">Get Started</button>
</form>
<?php
if (isset($_POST['submit'])) {
// Puts users in an array, and finds a userID that is not being used
$agentList = array();
$number = 1001;
foreach($users->find('start=0, roles=representative') as $v) {
array_push($agentList, $v->userID);
}
for ($number; ;) {
if(in_array($number, $agentList)) {
$number++;
} else {
$newAgentID = $number;
break;
}
}
// Place POST data into variables
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$fullName = array($firstName,$lastName);
$email = $_POST['email'];
//Have Processwire add the new user
$u = $users->add($firstName[0].$lastName);
$u->firstName = $firstName;
$u->lastName = $lastName;
$u->pass = "Password";
$u->addRole('representative');
$u->email = $email;
$u->userID = $newAgentID;
$u->save();
//Add user to ViciDial
$viciAdminUser = 10;
$viciAdminPass = "password";
$viciUser = $newAgentID;
$viciUserName = implode(" ",$fullName);
$viciUserPass = "Password".$newAgentID;
$viciUserLevel = 1;
$viciUserGroup = "Arizona";
}