ruth

I’m fairly sure I tried that, but I will try again 🙂

ruth

I’ve also tried $requiredFields->addRequiredField('SiteEmail[' . $i . ']'); Because I found that method in the api docs

ruth

Hopefully this makes more sense: The form gets the number of sites from another form, and returns a new form with fields to add all the sites (based on the number they have entered).

  1. $form = new Form(
  2. $this,
  3. 'FormName',
  4. $fields = FieldList::create(),
  5. FieldList::create(
  6. FormAction::create('send', 'Submit')
  7. ),
  8. $requiredFields = RequiredFields::create()
  9. );
  10. for ($i = 1; $i <= $numberOfSites; $i++) {
  11. //more fields are here
  12. $siteEmail = EmailField::create('SiteEmail[' . $i . ']', 'Email address');
  13. $form->Fields()->push(
  14. CompositeField::create(
  15. $siteEmail
  16. ));
  17. $requiredFields->push('SiteEmail[' . $i . ']');
  18. }
ruth

Hi all, I’m creating a form which has a for loop to create the certain number of fields (based on user input), I want all of the fields to be required, but I can’t push fields to RequiredFields() like you can with Fields(). It’s a fairly weird use case, so google has turned up nada. 😕 Anyone have any ideas?

ruth

So you have to account for that case too

ruth

I guess the problem is a member can be in many groups, so your code has to take that into account

ruth

If you want the person submitting the form to be able to select a group, you’d be better off using a DropdownField. I’m not sure why you’d want to show all the Groups if the user can’t do anything with it.

ruth

value is the 3rd argument in the Field construct. If you google “Silverstripe ReadOnlyField” you’ll find the docs page where it shows you the construct for Fields