<label for="activity">Activité <select name="activity:validFormActivity" id="activity" title="[[+error.activity]]" > <option value="[[+customFields.activity]]">[[+customFields.activity]]</option> <option value="1">Hotesse</option> <option value="2">Agent d'accueil</option> <option value="3">Mannequin</option> <option value="4">Steward</option> </select>
<?php
global $modx;
global $scriptProperties;
$tmp = $scriptProperties ['value'] ;
if ( (int ) $tmp > 0 ) {
$modx->setPlaceholders( array ('activity' => $tmp ), 'customFields.' );
} else {
return 'choose an option.<br />';
}
return true;
?>
<label for="otheractivity">Autre activité ( précisez )
<input type="text" name="otheractivity:validFormOtheractivity" id="otheractivity" value="[[+otheractivity]]"
title="[[+error.otheractivity]]" />
</label>
<?php
global $modx;
global $scriptProperties;
$tmp = $scriptProperties ['value'] ;
if ( strlen ( $tmp ) < 30 ) {
$modx->setPlaceholders( array ('otheractivity' =>'rrr'. $tmp ), 'customFields.' );
} else {
return '30 chars max<br />';
}
return true;
?>
<?php
$tmp = $scriptProperties['value'];
if (strlen($tmp) < 30) {
$modx->setPlaceholders(array('otheractivity' =>'rrr'. $tmp ), 'customFields.' );
} else {
$scriptProperties['validator']->errors[$scriptProperties['key']] = '30 chars max<br />';
return false;
}
return true;
1. Never use global in code.splittingred,
2. The $scriptProperties array and $modx object are automatically available for you. You dont need to global them.
global $modx;my functions do not work and I get this error:
global $scriptProperties;
Fatal error: Call to a member function getOption() on a non-object in /var/www/vhosts/mydomain.co.uk/httpdocs/modxfolder/assets/snippets/product/product.functions.inc.php on line 122The $scriptProperties array and $modx object seem to be available in the snippet and included files, but not from within functions. Is this correct behaviour?