Randomizer:
```
namespace app\widgets\randomizedForm;

use Yii;
use yii\web\Request;

use app\components\SessionManager;
use app\components\interfaces\SessionInterface;

/**
* Core service that generates randomized field names,
* stores them in session via SessionInterface,
* maps POST data back,
* and checks honeypot fields.
*/
class Randomizer
{
	/**
	* Session Manager Interface
	* @see app\components\interfaces\SessionInterface.php
	* @var SessionInterface
	*/
	protected SessionInterface $__session;
	
	// @var string The session key to use
	protected string $__sessionKey;
	
	// @var array<string,string>
	protected array $__fieldMap = [];
	
	/**
	* Construct
	* @param string $sessionKey
	* @param SessionInterface|null $session Allows internal creation if null.
	*/
	public function __construct(string $sessionKey, ?SessionInterface $session = null)
	{
		$this->__sessionKey = $sessionKey;
		$this->__session = $session ?? new SessionManager();
	}
	
	/**
	* Generate random string identifiers for given field list,
	* store in session and return the map.
	* @param list<string> $fields
	*
	* @return array<string,string> map logical field to randomized string
	*/
	public function generate(array $fields): array
	{
		$map = [];
		
		foreach ($fields as $field)
		{
			$map[$field] = $this->generateRandomString();
		}
		
		$this->__fieldMap = $map;
		$this->__session->set($this->__sessionKey, $map);
		
		return $map;
	}
	
	/**
	* Retrieve the map from session or return empty array
	* @return array<string,string>
	*/
	public function getMap(): array
	{
		if (empty($this->__fieldMap))
		{
			$stored = $this->_session->get($this->__sessionKey);
			$this->__fieldMap = is_array($stored) ? $stored : [];
		}
		
		return $this->__fieldMap;
	}
	
	/**
	* Reverse-map submitted POST data keys to logical attribute names.
	* @param array<string,mixed> $postData
	* @return array<string,mixed> mapped data in logical keys.
	*/
	public function mapPostData(array $postData): array
	{
		$map = $this->getMap();
		$reverseMap = array_flip($map);
		$mapped = [];
		
		foreach ($postData as $postKey => $value)
		{
			if (isset($reverseMap[$postKey]))
			{
				$mapped[$reverseMap[$postKey]] = $value;
			}
		}
		
		return $mapped;
	}
	
	/**
	* Check whether any honeypot fields are filled.
	* @param array<string,mixed> $mappedData
	* @param list<string> $honeypotFields
	* @return bool True if any honeypot field is filled, false otherwise.
	*/
	public function honeypotFilled(array $mappedData, array $honeypotFields): bool
	{
		foreach ($honeypotFields as $honeypot)
		{
			if (!empty($mappedData[$honeypot]))
			{
				return true;
			}
		}
		
		return false;
	}
	
	/**
	* Generate a random alphanumeric string
	* @param int $length
	* @return string
	*/
	protected function generateRandomString(int $length = 10): string
	{
		return substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyz0123456789', $length)), 0, $length);
	}
	
	/**
	* Instantiate Randomizer using session key from POST request,
	* fallback to default key, creates SessionManager internally if not passed.
	* @param SessionInterface|null $session Optional session manager.
	* @param Request|null $request Optional request object.
	* @return self
	*/
	public static function fromRequest(?SessionInterface $session = null, ?Request $request = null): self
	{
		$request = $request ?? \Yii::$app->request;
		$sessionKey = (string) $request->post('randomizedFormSessionKey', 'randomizedActiveFormFieldMap');
		
		return new self($sessionKey, $session);
	}
	
	/**
	* Get the session key currently used
	*/
	public function getSessionKey(): string
	{
		return $this->__sessionKey;
	}
	
	/**
	* Get access to session interface
	*
	public function getSession(): SessionInterface
	{
		return $this->__session;
	}//*/
}
```

RandomizedActiveForm:
```
namespace app\widgets\randomizedForm;

use Yii;
use yii\widgets\ActiveForm;
use yii\base\InvalidArgumentException as YiiBaseInvalidArgumentException;
use yii\web\View;
use yii\helpers\Json;

use app\components\SessionManager;
use app\components\interfaces\SessionInterface;
use app\components\traits\CacheJsCssTrait;
use app\widgets\randomizedForm\Randomizer;
use app\helpers\ParamHelper;
use app\helpers\TimeHelper;

/**
* RandomizedActiveForm overrides Yii2 ActiveForm to randomize all field names,
* store the mapping in session, and pass to fields.
*/
class RandomizedActiveForm extends ActiveForm
{
	/**
	* Placeholders keyed by logical attribute names.
	* To be set by the view when starting the widget.
	* @var array<string,string>
	*/
	public array $placeholders = [];
	
	// @var array<string, string> Map of logical attribute => randomized name
	public $fieldNameMap = [];
	
	// @var list<string> List of honeypot logical attribute names
	public $honeypotFields = [];
	
	//  @var object|null The form model
	public ?object $model = null;
	
	/**
	* Session Manager Interface
	* @see app\components\interfaces\SessionInterface.php
	* @var SessionInterface
	*/
	public SessionInterface $sessionManager = null;
	
	//  @var Randomizer
	protected Randomizer $__randomizer;
	
	// @var string The session key to use
	protected string $__sessionKey;
	
	// Note: Every protected variable below CacheJsCssTrait is used by the trait
	use CacheJsCssTrait;
	
	protected bool $__cacheDebugMode = false;
	protected bool $__compressJsCss = false;
	protected bool $__cacheEnable = false;
	protected int $__cacheJsCssTime = 3600;// +1 hour
	protected string $__cacheKeyPrefix = 'widget_randomizedActiveForm';
	
	const DEFAULT_DURATION_SECONDS = 3600;// +1 hour
	
	public function init(): void
	{
		// Get cacheDuration from Param and set with TimeHelper
		$cacheDuration = ParamHelper::get('widgets.cacheDuration');
		$this->__cacheJsCssTime = TimeHelper::convertDurationToSeconds($cacheDuration);
		
		// Cache & Compression
		$this->__cacheEnable = ParamHelper::get('widgets.cacheEnable');
		$this->__compressJsCss = ParamHelper::get('widgets.compressJsCss');
	
		/**
		* Always call the parent init method first to ensure any
		* initialization logic defined in the base class is executed first.
		*/
		parent::init();
		
		// Initialize sessionManager internally if not set
		if (!isset($this->sessionManager))
		{
			$this->sessionManager = new SessionManager();
		}
		
		if ($this->model === null)
		{
			throw new YiiBaseInvalidArgumentException(
				'RandomizedActiveForm requires you to set the "model" property.'
			);
		}
		
		if (empty($this->__sessionKey))
		{
			$this->__sessionKey = 'randomMap_' . \Yii::$app->security->generateRandomString(16);
		}
		
		$this->__randomizer = new Randomizer($this->__sessionKey, $this->sessionManager);
		
		// Combine model attributes and honeypots
		$attributes = array_keys($this->model->attributes);
		$logicalFields = array_merge($attributes, $this->honeypotFields);
		
		// Retrieve existing field map or generate new randomized names
		$this->fieldNameMap = $this->__randomizer->getMap();
		
		if (empty($this->fieldNameMap))
		{
			$this->fieldNameMap = $this->__randomizer->generate($logicalFields);
		}
	}
	
	public function run(): void
	{
		// Output hidden input with __sessionKey before form end tag
		echo Html::hiddenInput('randomizedFormSessionKey', $this->__sessionKey);
		
		// Register JS for dynamically applying placeholders if any provided
		if (!empty($this->placeholders))
		{
			$this->registerPlaceholderScript($this->placeholders);
		}
		
		parent::run();
	}
	
	/**
	* Register JS code to fill placeholders for randomized input names.
	* @param array<string,string> $placeholders
	* @return void
	*/
	private function registerPlaceholderScript(array $placeholders): void
	{
		if (empty($this->fieldNameMap) || empty($placeholders))
		{
			return;
		}
		
		$fieldMapJson = Json::htmlEncode($this->fieldNameMap);
		$placeholdersJson = Json::htmlEncode($placeholders);
		$cacheKey = $this->__cacheKeyPrefix . $widgetId . '_js_block_';
		
		$jsBlock = $this->getCachedJsBlock($cacheKey, function () use (
			$fieldMapJson,
			$placeholdersJson
		)
		{
			return <<<JS
			(function(\$)
			{
				\$(function()
				{
					var map = $fieldMapJson;
					var placeholders = $placeholdersJson;
					
					Object.keys(map).forEach(function(logicalName)
					{
						var randomized = map[logicalName];
						var el = document.querySelector('[name="' + randomized + '"]');
						
						if (el && placeholders[logicalName])
						{
							el.setAttribute('placeholder', placeholders[logicalName]);
						}
					});
				});
			})(jQuery);
			JS;
		});
		
		// Register the JavaScript.
		$this->getView()->registerJs($jsBlock, View::POS_END);
	}
	
	/**
	* Override ActiveForm::field() to pass randomized fieldNameMap to ActiveField
	* @param object $model
	* @param string $attribute
	* @param array $options
	* @return \yii\widgets\ActiveField
	*/
	public function field($model, string $attribute, array $options = []): ActiveField
	{
		$options['fieldNameMap'] = $this->fieldNameMap;
		
		return parent::field($model, $attribute, $options);
	}
	
	/**
	* Get the Randomizer instance, for convenience
	*/
	public function getRandomizer()
	{
		return $this->__randomizer;
	}
}
```

RandomizedActiveField:
```
declare(strict_types=1);

namespace app\widgets\randomizedForm;

use Yii;
use yii\widgets\ActiveField;

/**
* RandomizedActiveField overrides Yii2 ActiveField to render inputs with 
* randomized 'name' attributes using the fieldNameMap populated by 
* RandomizedActiveForm.
*/
class RandomizedActiveField extends ActiveField
{
	// @var array randomized map of attribute => randomized name
	public array $fieldNameMap = [];
	
	/**
	* Internal helper to override the 'name' attribute if randomized
	* @param array<string,mixed> $options
	* @return array<string,mixed>
	*/
	protected function applyRandomName(array $options): array
	{
		if ($this->fieldNameMap !== [] && isset($this->fieldNameMap[$this->attribute]))
		{
			$options['name'] = $this->fieldNameMap[$this->attribute];
		}
		
		return $options;
	}
	
	/**
	* @inheritDoc
	*/
	public function input(string $type, array $options = []): string
	{
		$options = $this->applyRandomName($options);
		
		return parent::input($type, $options);
	}
	
	/**
	* @inheritDoc
	*/
	public function textInput(array $options = []): string
	{
		return $this->input('text', $options);
	}
	
	/**
	* @inheritDoc
	*/
	public function passwordInput(array $options = []): string
	{
		return $this->input('password', $options);
	}
	
	/**
	* @inheritDoc
	*/
	public function hiddenInput(array $options = []): string
	{
		return $this->input('hidden', $options);
	}
	
	/**
	* @inheritDoc
	*/
	public function checkbox(array $options = []): string
	{
		$options = $this->applyRandomName($options);
		
		return parent::checkbox($options);
	}
	
	/**
	* @inheritDoc
	*/
	public function checkboxList(array $items, array $options = []): string
	{
		$options = $this->applyRandomName($options);
		
		return parent::checkboxList($items, $options);
	}
	
	/**
	* @inheritDoc
	*/
	public function radio(array $options = []): string
	{
		$options = $this->applyRandomName($options);
		
		return parent::radio($options);
	}
	
	/**
	* @inheritDoc
	*/
	public function radioList(array $items, array $options = []): string
	{
		$options = $this->applyRandomName($options);
		
		return parent::radioList($items, $options);
	}
	
	/**
	* @inheritDoc
	*/
	public function dropDownList(array $items, array $options = []): string
	{
		$options = $this->applyRandomName($options);
		
		return parent::dropDownList($items, $options);
	}
	
	// etc...
}

```

How it should work in view:
```
use app\widgets\RandomizedForm\RandomizedActiveForm;
use app\widgets\RandomizedForm\RandomizedActiveField;

/* @var $model \app\models\RegisterForm */

$form = RandomizedActiveForm::begin([
    'id' => 'register-form',
    'fieldClass' => RandomizedActiveField::class,
    'model' => $model,
    'honeypotFields' => ['honeypot1', 'honeypot2'],
    // no sessionManager here — it's created internally
    'enableClientValidation' => true,
]);

echo $form->field($model, 'email')->input('email');
echo $form->field($model, 'password')->passwordInput();
echo $form->field($model, 'username')->textInput();

foreach ($form->honeypotFields as $hp) {
    echo $form->field($model, $hp)->textInput([
        'style' => 'position:absolute; left:-9999px;',
        'tabindex' => '-1',
        'autocomplete' => 'off',
        'aria-hidden' => 'true',
    ]);
}

RandomizedActiveForm::end();
```

and controller
```
use app\widgets\RandomizedForm\Randomizer;
use Yii;
use yii\web\Response;

public function actionRegister(): string|Response
{
    $request = Yii::$app->request;

    if ($request->isPost) {
        // No need to create SessionManager, it's done internally
        $randomizer = Randomizer::fromRequest();

        $honeypots = ['honeypot1', 'honeypot2'];
        $post = $request->post();
        $mappedData = $randomizer->mapPostData($post);

        if ($randomizer->honeypotFilled($mappedData, $honeypots)) {
            Yii::$app->session->setFlash('error', 'Bot activity detected.');
            return $this->refresh();
        }

        $model = new \app\models\RegisterForm();

        if ($model->load($mappedData, '') && $model->validate()) {
            $randomizer->session->remove($randomizer->getSessionKey());
            return $this->redirect(['site/success']);
        }

        return $this->render('register', ['model' => $model]);
    }

    $model = new \app\models\RegisterForm();
    return $this->render('register', ['model' => $model]);
}
```

Im trying to refactor my actionContact and contact view to see if I can get my randomizedForm code to work but i want your help

```
public function actionContact(string $subject = null): Response|string
	{
		// Set Page title for the browser tab/page title and page header.
		$pageTitle = \Yii::t('app', 'contact us');
		// Set Meta Data for website title, keywords, description and prepend site name(bool).
		$this->setMeta($pageTitle, 'contact, contact us');
		// Set page breadcrumbs. (optional)
		//\Yii::$app->layoutManager->addBreadcrumb($pageTitle);// page now.
		
		
		// Setup $model.
		if ($this->_isGuest)
		{
			$model = new ContactForm();
			if ($subject === null)
			{
				$model->subject = $subject = '';
			}
			
			$model->subject = $subject;
		}
		else
		{
			$user = RoleHelper::userIdentity();
			
			$model = new ContactForm();
			// Firstname, lastname and email are all required feilds
			$model->name = $user->firstname . ' ' . $user->lastname;
			$model->email = $user->email;
			if ($subject === null)
			{
				$model->subject = $subject = '';
			}
			
			$model->subject = $subject;
		}
		
		$request = \Yii::$app->request;
		if ($request->isPost)
		//if (($request->isPost) && ($model->load($request->post()) && $model->validate()))
		{
			// No need to create SessionManager, it's done internally
			$randomizer = Randomizer::fromRequest();
			$post = $request->post();
			$mappedData = $randomizer->mapPostData($post);
			
			if ($randomizer->honeypotFilled($mappedData, $honeypots))
			{
				\Yii::$app->session->setFlash('error', 'Bot activity detected.');
				
				return $this->refresh();
			}
			
			
			
			// Perform the post-validation action.
			if ($model->process())
			{
				/**
				* HoneyPot
				* The 'honeyPot' field is a honeypot, designed to trap bots by 
				* mimicking a legitimate field.
				*/
				if ($this->_honeyPot && $model->emaill)
				{
					LogHelper::logBotAction('Honeypot. Potential bot detected', [
						'ip' => $this->_userIp,
						'userAgent' => $this->_userAgent,
					]);
				}
				
				AlertHelper::setFlash(
					'success',
					\Yii::t(
						'app', 
						'<h4 class="alert-heading">Thank You</h4>
						<p>Thank you for contacting us. We will respond to your inquiry as soon as possible.</p>'
					),
					5000
				);
				
				// Handle the POST-Redirect-GET pattern.
				return $this->refresh();
			}
			else
			{
				AlertHelper::setFlash('error', ErrorMessageHelper::processingError(), 8000);
			}
		}
		
		// Re-rendered regardless of whether there was an error or if the form validation failed.
		return $this->render('contact', [
			//'pageTitle' => $pageTitle,
			'model' => $model,
		]);
	}
```

```
<div class="site-contact">
<div class="row justify-content-center">

<div class ="col col-sm-10 col-md-8 col-lg-6">
<?php
/*<h4 class="text-center mb-4"><?= \Yii::t('app', 'Contact Us'); ?></h4>*/
$form = ActiveForm::begin([
	'id' => 'contact-form',
	'action' => ['site/contact'],
	'method' => 'post',
	'options' => ['class' => 'active-form mx-auto'],
]);
?>
<div class="row">
<p><?= \Yii::t('app', 'If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.'); ?></p>

<div class="col-md-6 mb-2">
<?= $form->field($model, 'name')->textInput([
	'class' => 'form-control square',
	'placeholder' => \Yii::t('app', 'Enter Name'),
	'autofocus' => true
])->hint(\Yii::t('app', 'optional')); ?>
</div><!-- .col-md-6 .mb-2 -->

<div class="col-md-6 mb-2">
<?= $form->field($model, 'email')->textInput([
	'class' => 'form-control square',
	'placeholder' =>  \Yii::t('app', 'Enter email'),
]); ?>
</div><!-- .col-md-6 .mb-2 -->

</div><!-- .row -->
<div class="row">

<?php /*<div class="col-md-6 mb-2">
<label for="phone" class="form-label">Phone Number</label>
<input type="text" class="form-control square" id="phone">
</div><!-- .col-md-6 .mb-2 -->*/ ?>

<div class="col-md-12 mb-2">
<?= $form->field($model, 'subject')->textInput([
	'class' => 'form-control square',
	'placeholder' =>  \Yii::t('app', 'Enter subject'),
]); ?>
</div><!-- .col-md-12 .mb-2 -->

</div><!-- .row -->
<div class="row">

<div class="col-md-12 mb-2">
<?= $form->field($model, 'body')->textarea([
	'class' => 'form-control square',
	'rows' => 8,
	'placeholder' =>  \Yii::t('app', 'Type your message here...'),
]); ?>
</div><!-- .col-md-12 .mb-2 -->

<div class="col-md-12 mb-2">
<?php
$verifyHint = \Yii::t('app', 'Click the image to reload a new verification code.');
echo $form->field($model, 'verifyCode')->label(\Yii::t('app', 'Enter Security Code'))->widget(Captcha::class, [
    'imageOptions' => [
        'title' =>  \Yii::t('app', 'Click to refresh'),
        'class' => 'mb-1',
    ],
    'options' => [
        'class' => 'form-control square',
    ],
    'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
])->hint($verifyHint);
?>
</div><!-- .col-md-12 .mb-2 -->


<div class="text-left col-12 col-md-auto">
<?= Html::submitButton(\Yii::t('app', 'Submit'), [
	'class' => 'btn btn-primary square w-100 w-md-auto',
	'name' => 'contact-button',
]); ?>
</div><!-- .text-left .col-12 .col-md-auto -->

</div><!-- .row -->
<?php ActiveForm::end(); ?>
</div><!-- .active-form .col .col-sm-10 .col-md-8 .col-lg-6 -->

</div><!-- .row .justify-content-center -->
</div><!-- .site-contact -->
```

think you can help refactor my contact view/controller?