Custom form field not working (PGF)

Dinocanid

Artist
I'm attempting to add a field into the breed creator in the admin panel where you can set a minimum and maximum height for that breed. However, it refuses to work, and the strange thing is that it did before. For a while it was working, and one day it stopped (and the code hadn't even been touched).

if ($game->buttonPressed('addBreed')) {
$_MESSAGES[] = $game->session('player')->addBreed(
$game->post('name'),
$game->post('species'),
$game->post('url'),
$game->post('info'),
$game->post('min_height'),
$game->post('max_height'),
$game->post('cross_one'),
$game->post('cross_two')
);
}


(breeds.php when the button is pressed)

<div class="form-row">
<div class="form-group col-md-6">

<label for="minheight">
' . __MIN_HEIGHT .':
</label>
<i class="' . __ICON_DEFAULT . '"></i>
<input
type="text"
name="min_height"
id="min_height"
class="form-control"
value="' . $breed->minHeight() . '" />
</div>


<div class="form-group col-md-6">

<label for="maxheight">
' . __MAX_HEIGHT .':
</label>
<i class="' . __ICON_DEFAULT . '"></i>
<input
type="text"
name="max_height"
id="max_height"
class="form-control"
value="' . $breed->maxHeight() . '" />
</div>
</div>


(HTML from the form in breeds.php)

public function add($name, $species, $url = null, $info = null, $min_height, $max_height, $cross_one = null, $cross_two = null)
{
echo "Min: {$min_height}, Max: {$max_height}";
//etc. rest of the code is here...
}


(add function in Breed.php)

The minimum and maximum height always return blank, and only those fields (please ignore the weird indentation, TGL makes it weird for some reason). The only way it works now is if min_height and max_height are hard-coded in the add function params, which of course isn't good for this case.

(Design1online was contacted about this btw, but wasn't able to give a working solution)

 
Honestly it's a bit hard to follow as I am not very familiar with PGF. Does addBreed really call the add method directly? 

One thing to do for trouble shooting is jump back a step. So you see add isn't given the expected results, jump back to the first place the input in grabbed. So wherever the form submits, and check there. If the input is as expected continue down the line until you find the area where it's not what you expect and then you can more easily figure out what is going wrong. 

A side note, your labels are marked for ids that don't exist. minheight should be min_height or the id should be minheight anyway. Wouldn't effect what your doing, but important for it to actually be tied to the correct form element.

 
Oh yeah I fixed the id thing already (an oversight, whoops), but addBreed does directly call the add function.

I already did the backtracking and the input html is correctly linked, just like all the other inputs, but the inputted value isn't being sent for some reason. It's been driving me insane for weeks lol. Especially since it used to work perfectly fine.

 
Have you tried hard-coding what you send through addBreed or just within the add functionality?

If the hard code works, then something is wrong with the input (not likely since you checked that but sometimes), and if not then something is probably wrong with whatever is making addBreed call add instead. 

One thing you could try, especially if there may be something else interfering, like the framework naming magic, is to just change the name of the method you are calling, or create a new method with a different name (same parameters) and call that instead. And of course you should get the values you input in, and would confirm it is something going wrong with the original function. 

Edit:

Yeah that is weird it was working before and not now. Something must have changed and you didn't realize, or it didn't actually work. If you use version control tracking you can check the logs. And sometimes something that seems unrelated will have changed and mess things up.

 
Last edited by a moderator:
Something really weird is just going on with the params o.0 I literally copy-pasted the echo code into a new function and it works, but it won't work with the add function. So yeah I have no idea what's going on.
 

public function addtest($min_height, $max_height)
{
echo "Min: {$min_height}, Max: {$max_height}";
}


This work-around works so I guess it's fine. I wish I could keep the height params in the same function as everything else though.

Aaaaand now the add function suddenly works, and I didn't even touch it. Wha
At least it's fixed now.

 
Last edited by a moderator:
Well you do have something weird going on, as addBreed doesn't equal add in the first place so if you are hitting add something has to be tying the two together. Which I don't know what exactly that is or why, but perhaps renaming it 'reset' that connection or something assuming it is something generated. 

 
Back
Top