Jump to content

Установка настраиваемого поля в качестве обязательного поля

Featured Replies

Posted

Я использую настраиваемые поля как для приложения под названием Application Forms, так и для Commerce.

Почти все настраиваемые поля имеют возможность установить их как обязательные поля, за исключением некоторых. В моем случае я хочу, чтобы «флажок» действовал как обязательное поле.

Я пошел в system > CustomField и отредактировал CustomField.php. Я смог показать параметр обязательного поля, но он просто не работает. Это просто визуально.

Показать контент

Я также пошел в system > Helpers > Form > Checkbox.php, но я понятия не имею, что там редактировать. 😅

  • Author
  On 28.02.2022 at 22:28, by_ix said:

разве что для принятия псевдоправил.

Хороший вопрос, и если я правильно понял, то это и есть ответ. Я хочу сделать это обязательным полем, тогда как форма не будет отправлена, если пользователь не установил флажок. Что-то вроде согласия с условиями обслуживания, понимаете?

  On 28.02.2022 at 21:22, BlackShot said:

Слишком много работы?

Yep. You can insert such a field manually

$form->add( new \IPS\Helpers\Form\Checkbox( 'agreed_terms_lang', FALSE, TRUE, array( ), function( $val )
{
	if ( !$val ) { 
 		throw new \InvalidArgumentException('agreed_terms_warn'); 
	}
}, NULL ) );

 

  • Author
  On 01.03.2022 at 09:11, Desti said:

Yep. You can insert such a field manually

$form->add( new \IPS\Helpers\Form\Checkbox( 'agreed_terms_lang', FALSE, TRUE, array( ), function( $val )
{
	if ( !$val ) { 
 		throw new \InvalidArgumentException('agreed_terms_warn'); 
	}
}, NULL ) );

 

I've added it to the proper file and unset its value - it works! The only downside to this is it adds a checkbox for every form created, whereas I only wanted it to show for specific ones. But that's still better than changing so much code, right? Thanks, Desti 🏆

You can create new settings (array ), for example "showConfirmCheckbox" (in App...Form application), add number of your forms with checkbox ( [2,3,6] ) and use this settings for enable-disable checkbox. 

if( \in_array( \IPS\Request::i()->id, \IPS\Settings::i()->showConfirmCheckbox ) ) {
  $form->add( new \IPS\Helpers\Form\Checkbox......
}

 

  • Author
  On 01.03.2022 at 23:16, Desti said:

You can create new settings (array ), for example "showConfirmCheckbox" (in App...Form application), add number of your forms with checkbox ( [2,3,6] ) and use this settings for enable-disable checkbox. 

if( \in_array( \IPS\Request::i()->id, \IPS\Settings::i()->showConfirmCheckbox ) ) {
  $form->add( new \IPS\Helpers\Form\Checkbox......
}

Genius! I'll try that soon and let you know if I had success. 

PS: I completed a basic PHP course and now I'm trying to study object oriented PHP like you recommended, but I still feel like it's going to be a loooong fucking journey. Shit is difficult. I'm trying though. xD

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Ответить в этой теме...

Последние посетители 0

  • No registered users viewing this page.