Formit url parameters lost after validation

Hello everybody.

I’m using formit to send an email from a form.
I’m filling one of the input fields with an url parameter using a prehook:



urlParam (snippet):

    $urlParam = $_GET ['parameterhere'];
    $modx->setPlaceholder('parameterhere', $urlParam);

Input field:
<input type="hidden" name="code" value="[[+parameterhere]]" />

Everything is working fine until here, the problem is after validation:


If validation fails the form page reload and the parameters disappear, so the field have not parameter to send so nothing works.

any help please?
Thanks! :+1:

You could change the code of your input field to something like this.

<input type="hidden" name="code" value="[[!+fi.code:isempty=`[[!+parameterhere]]`]]" />

Alternatively, you could change your snippet urlParam to read the right $_POST parameter if the $_GET parameter doesn’t exist:

if (isset($_GET['parameterhere'])){
	$modx->setPlaceholder('parameterhere', $_GET['parameterhere']);
} else if (isset($_POST['code'])){
	$modx->setPlaceholder('parameterhere', $_POST['code']);

Or maybe you could just always add the get-parameter to your form action url.

<form method="post" action="[[~[[*id]]]]?parameterhere=[[!+parameterhere]]">
1 Like

This has to be called uncached. And your preHook has to check whether the form was posted ($_POST is not empty then). Finally you should work with $hook->setValue instead of $modx->setPlaceholder.

This option work just fine mate thanks!
<input type="hidden" name="code" value="[[!+fi.code:isempty=[[+parameterhere]]]]" />

Thanks @jako for your help too mate.


Please change the value attribute to:


1 Like