best practise how to set form custom values after send form?

Notice: This thread is very old.
mcmatak
Member | 490
+
0
-

example:
I need to reload form based on changed any value (user id), this should lead to changed credentials and address of new user (this use should be load from database).

this is my code in createComponentForm()

		$form->setDefaults($defaults);

		// _changeByIdUser, chceme nacist fakturacni a dodaci adresu podle uzivatele, musi byt az tady po setnuti defaultu
		$post = $this->getRequest()->getPost();
		if (isset($post['_reloadEditControl_params'])) {
			parse_str($post['_reloadEditControl_params'], $_params);
			if (isset($_params['changeByIdUser']) && $_params['changeByIdUser'] == 1 && isset($post['idUser']) && ($idUser = trim($post['idUser']))) {
				if ( ($userProfileAddress = \App\Models\UserProfileAddress::find($idUser)) ) {
					$form['name']->setValue($userProfileAddress->name);
					$form['company']->setValue($userProfileAddress->company);
					$form['ICO']->setValue($userProfileAddress->ICO);
					$form['DIC']->setValue($userProfileAddress->DIC);
				}
			}
		}

also this code doesnt work

Last edited by mcmatak (2014-01-23 21:48)

mcmatak
Member | 490
+
0
-

this works

	/**
	 * @User(allowed="THIS/default=read")
	 */
	public function renderEdit()
	{
		parent::renderEdit();

		// _changeByIdUser, chceme nacist fakturacni a dodaci adresu podle uzivatele, musi byt az tady po setnuti defaultu
		$post = $this->getRequest()->getPost();
		if (isset($post['_reloadEditControl_params'])) {
			parse_str($post['_reloadEditControl_params'], $_params);
			if (isset($_params['changeByIdUser']) && $_params['changeByIdUser'] == 1 && isset($post['idUser']) && ($idUser = trim($post['idUser']))) {
				if ( ($userProfileAddress = \App\Models\UserProfileAddress::find($idUser)) ) {
					$form = $this['editControl']['editForm'];
					$form['name']->setValue($userProfileAddress->name);
				}
			}
		}
	}

it is not very clean by my opinion, but it works, the problem is that in factory createComponent the $post is set and cant be changed, also the value of form elements will be overwritten later, so the only chance is to change it after form is created

some best practice to do this?