Express: Adding form controls programatically ->how to set form Fields to 'is_required'

Permalink
Has some an approach how to set a created form attribute to 'is_required ->1'.
Is there any method to do so?

I have researched all documents and posts regarding
https://documentation.concrete5.org/developers/express/programmatica...
however couldn'Ät find any hint.

 
linuxoid replied on at Permalink Reply
linuxoid
e.g.
echo $form->text('name'.$bUID, $name, array ('maxlength'=>"60", 'required'=>"required", 'data-tag'=>'name'));

https://documentation.concrete5.org/tutorials/how-to-use-the-form-wi...
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi MichT,

There is a setIsRequired() method in the Control class.
concrete\src\Entity\Express\Control\Control.php

I am not sure how to use it when creating Express objects programmatically (or if it is the correct method to use).
MichT replied on at Permalink Reply
Hi MrKDilkington,
thx for reply. Had found this class myself, but had no result in trying to implement it.
Found a probably bit 'hacky' solution that works in 8.3.1.
Here a working script for a package controller (install or upgrade routine):
1. Makes a contact form
2. Creates an Express-Form-Block and puts it in place
3. Sets all created input fields.

//WORKS WITH CONCRETE_5 VER. 8.3.1
      use page;
use Block;
      use BlockType;
      use Express;
      $page = Page::getByID(HOME_CID);
        //MAKE CONTACT FORM
        $formExpressObject = Express::getObjectByHandle('kontakt');
        if (is_object($formExpressObject)) {
            throw new Exception(t('An express object with this handle already exists.'));
        } else {
            $attrKeys = array(
                'keyName'       => 'name',
                'keyEmail'      => 'email',
                'keyMessage'    => 'message'