<p>Thanks to Brad Bell, I was able to troubleshoot using <code>var_dump</code>. The code above works correctly, but I'm unaware of how to do a simple validation of the code within the controller, w/o creating a new model, &amp; send back a response.</p>

<p>Instead (for simplicity on my end), when the validation fails, I redirected to an error specific page, referencing the code entered &amp; team name.</p>

CC BY-SA 3.0
2015-04-08T14:19:20.877Z
Another option to consider is to call your controller via ajax and send back a response — you can then set the error via javascript, and maintain the data that the user has already been entered.
Douglas McDonald
CC BY-SA 3.0
2015-04-07T18:49:38.533Z
2015-04-07T18:49:38.533Z
Chase Giunta
<p>Whoo, that title is a mouthful...</p>

<p>I'm trying to check against a unique school "code" that an athlete has to input to register with a team. The code is different based on what team they are trying to join (referenced in a segment of registration page URL). I have no idea what I'm doing when it comes to PHP or plugins but I hope I'm on the right track. I have no idea how to test what values my variables have.</p>

<p>I've essentially copied the <code>user/SaveUser</code> controller into my own plugin (I have to place user in Athlete user group &amp; related the specific team entry to user, hence custom plugin) and placed snippet below right before the <code>if (craft()-&gt;users-&gt;saveUser($user))</code> line.</p>

<pre><code>$teamName = craft()-&gt;request-&gt;getPost('fields.teamName');
//Get team name, set in hidden input in form, which was grabbed from segment


$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'teams';
$criteria-&gt;title   = $teamName;
$criteria-&gt;limit   = 1;
$entry = $criteria-&gt;first();
//Find the Team entry in my 'teams' section

$schoolCode = $entry-&gt;schoolCode;
//Place value of schoolCode field in variable

$codeInput = craft()-&gt;request-&gt;getPost('fields.schoolCode');
//Grab user's input

if ($schoolCode == $codeInput)
{ 
    craft()-&gt;users-&gt;saveUser($user)
}
</code></pre>

<p>This is, of course, not working. I'm not getting any errors either.</p>

<p>Am I anywhere close to doing this right?</p>

CC BY-SA 3.0
2015-04-07T02:19:17.820Z
I'd start by `var_dump`ing some variables to see if they have the values you're expecting. `$teamName`, `$schoolCode` and `$codeInput` as a starting point.
Brad Bell
CC BY-SA 3.0
2015-04-07T18:51:43.320Z
Ah, `var_dump` - I knew there had to be a simple way... That helped. I figured I would have botched the plugin code.
Chase Giunta
<plugin-development><registration><entries-field>
Compare custom-field value of entry to registration-form field value before saving user
# Compare custom-field value of entry to registration-form field value before saving user

(Asked by: username_0 on 2015-04-06)

Whoo, that title is a mouthful...
I'm trying to check against a unique school "code" that an athlete has to input to register with a team. The code is different based on what team they are trying to join (referenced in a segment of registration page URL). I have no idea what I'm doing when it comes to PHP or plugins but I hope I'm on the right track. I have no idea how to test what values my variables have.
I've essentially copied the user/SaveUser controller into my own plugin (I have to place user in Athlete user group & related the specific team entry to user, hence custom plugin) and placed snippet below right before the if (craft()->users->saveUser($user)) line.
$teamName = craft()->request->getPost('fields.teamName');
//Get team name, set in hidden input in form, which was grabbed from segment


$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'teams';
$criteria->title   = $teamName;
$criteria->limit   = 1;
$entry = $criteria->first();
//Find the Team entry in my 'teams' section

$schoolCode = $entry->schoolCode;
//Place value of schoolCode field in variable

$codeInput = craft()->request->getPost('fields.schoolCode');
//Grab user's input

if ($schoolCode == $codeInput)
{ 
    craft()->users->saveUser($user)
}

This is, of course, not working. I'm not getting any errors either.
Am I anywhere close to doing this right?

**Tags:** plugin-development, registration, entries-field
> **Comments:**
> **username_1**: I'd start by `var_dump`ing some variables to see if they have the values you're expecting. `$teamName`, `$schoolCode` and `$codeInput` as a starting point.  
> **username_0**: Ah, `var_dump` - I knew there had to be a simple way... That helped. I figured I would have botched the plugin code.  

---

## 1 answers

### Answer by username_0 on 2015-04-07. Score: 1 | Accepted answer

Thanks to Brad Bell, I was able to troubleshoot using `var_dump`. The code above works correctly, but I'm unaware of how to do a simple validation of the code within the controller, w/o creating a new model, & send back a response.

Instead (for simplicity on my end), when the validation fails, I redirected to an error specific page, referencing the code entered & team name.

> **Comments:**
> **username_2**: Another option to consider is to call your controller via ajax and send back a response — you can then set the error via javascript, and maintain the data that the user has already been entered.  

---

