Field "required"

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

I would like to make the “telephone” field “required” in the contact form on this page Installatori Suntek » suntekItalia

how can I do ?

Thank You

Welcome to the forum!

Could you post the code which is generating your form? (Presumably it’s in the controller)
You might just need to include it in the required fields (Introduction to Forms – SilverStripe Documentation)
but it’s a bit hard to know for sure without seeing some code.

hi, could be this?

<% if $Message %>

$Message

<% else %> <% end_if %>

Compila il form per ricevere l’indirizzo del tuo rivenditore

Cerca per provincia

$Fields.dataFieldByName(Provincia) $Fields.dataFieldByName(Nome) $Fields.dataFieldByName(Cognome) $Fields.dataFieldByName(Cellulare) $Fields.dataFieldByName(Email) $Fields.dataFieldByName(Pagina)

$Fields.dataFieldByName(Privacy) $Fields.dataFieldByName(Privacy).Title

$Fields.dataFieldByName(SecurityID) $Fields.dataFieldByName(Telephone) <% if $Actions %>

<% loop $Actions %>$Field<% end_loop %>

<% end_if %>

No it is not. It should be a php method public function YourForm() Try to understand Introduction to Forms – SilverStripe Documentation

in your form methode you can do something like $required = new RequiredFields('telephone'); and pass it to your form constructor.

in wich folder?

It should be in mysite i guess it will be one of your PageControllers. It depends on how you did it. I‘d go to the template where the form is rendert and look for the name of the Form variable $YourForm(what ever the form name is)and than search for the name of the form without the $ in your ide in the mysite folder. You should find a methode with that name.

<?php class RivenditoriPage extends Page{ public function canCreate($member = NULL) { if(RivenditoriPage::get()->first()) return false; return true; } } class RivenditoriPage_Controller extends Page_Controller{ private static $allowed_actions = array ( "RivenditoriForm" ); public function RivenditoriForm() { $items = DB::query("SELECT Province AS ID, Province FROM Province ORDER BY Province"); $fields = new FieldList( DropdownField::create('Provincia','', $items->map("Province", "Province"))->setEmptyString("Seleziona una provincia *"), TextField::create('Nome')->setAttribute("placeholder", "Nome *"), TextField::create('Cognome')->setAttribute("placeholder", "Cognome *"), TextField::create('Cellulare')->setAttribute("placeholder", "Cellulare"), EmailField::create('Email')->setAttribute("placeholder", "Email *"), new HiddenField("Pagina", "Pagina", $this->Title), new TextField("Telephone"), $this->getCheckboxPrivacy() ); $actions = new FieldList( FormAction::create("doRivenditoriForm", "Cerca il rivenditore")->addExtraClass("btn btn-success btn-lg") ); $validator = new RequiredFields(array("Provincia", "Nome", "Cognome", "Email", "Privacy")); $form = new Form($this, 'RivenditoriForm', $fields, $actions, $validator); $form->setAttribute("novalidate", "novalidate"); $form->setTemplate("RivenditoriForm"); $form->setRedirectToFormOnValidationError(true); return $form; } public function doRivenditoriForm($data, $form) { if($data["Telephone"] == ""){ $this->SendEmail($data); $this->SendAdminEmail($data); $this->redirect($this->Link("result")); } } }

Do you still need help? Just in case: add ‘telephone’ to the array.

thank you Greg for you support,
have a nice day

1 Like