/** * @param int $length * @return string */ public static function randString($length = 6) { static $rs = false; static $count = 0; if (!$rs) { $count++; $seed = md5($_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI']) . $count; $rs = new \Bitrix\Main\Type\RandomSequence($seed); } return $rs->randString($length); }
public static function GetForm($form_params, $container_id, $ajax_id, $bReplace = true, $bShadow = true) { static $rndGenerator = null; if (!$rndGenerator) { $rndGenerator = new \Bitrix\Main\Type\RandomSequence("BX_AJAX"); } $rnd = $rndGenerator->randString(6); return ' <form ' . trim($form_params) . '><input type="hidden" name="' . BX_AJAX_PARAM_ID . '" id="' . BX_AJAX_PARAM_ID . '_' . $ajax_id . '_' . $rnd . '" value="' . $ajax_id . '" /><input type="hidden" name="AJAX_CALL" value="Y" /><script type="text/javascript"> function _processform_' . $rnd . '(){ var obForm = top.BX(\'' . BX_AJAX_PARAM_ID . '_' . $ajax_id . '_' . $rnd . '\').form; top.BX.bind(obForm, \'submit\', function() {' . CAjax::GetFormEventValue($container_id, $bReplace, $bShadow, '"') . '}); top.BX.removeCustomEvent(\'onAjaxSuccess\', _processform_' . $rnd . '); } if (top.BX(\'' . BX_AJAX_PARAM_ID . '_' . $ajax_id . '_' . $rnd . '\')) _processform_' . $rnd . '(); else top.BX.addCustomEvent(\'onAjaxSuccess\', _processform_' . $rnd . '); </script>'; }