MODX Community

[hook] Set placeholder with dynamic input name

I’m trying to get an input field value and save it into a placeholder using a hook.
The normal process is something like this:

<input type="text" name="score" id="score" value="000">


$score = $hook->getValue('score');

Then I can call the value using the [[+score]] placeholder.

But I’m using formalicious, in order to save a field into formIt it’s necessary to use [[!+id]] in the name field:

<input type="text" name="field_[[!+id]]" id="score" value="000">

that makes the name dynamic and can’t use the:

$score = $hook->getValue('score');

How can I get the value of that input field?
Thanks for your help!

1 Like

There is no option to custom name the fields?

It’s a longshot but you can filter your inputs on integers and get the score.

Try something like


// enter the name of the input you want to capture i.e. score (without the _[[+id]])
$name = $modx->getOption('inputName', $hook->formit->config, 'score');

foreach($hook->getValues() as $k => $v) {
    if (strpos($k, $name) !== false) {
        $modx->setPlaceholder($name, $v);

Use it like


The biggest issue with this is it will match (and overwrite) anything like scores, score-card etc but should point you in the right direction