2016-08-18 3 views
1

Silverstripe에서 프런트 엔드 양식을 만들었습니다. 데이터를 기록한다는 의미에서 작동하며, 오류가있는 경우 다시 리디렉션하고 데이터를 저장하지 않습니다. 그러나 내가 직면하고있는 문제는 유효성 검사 메시지가 올바르게 표시되지 않는다는 것입니다. $Form 변수를 사용하여 프런트 엔드에 양식을 표시하면 유효성 검사가 제대로 작동합니다. 내가 원하는 것은 <% control Form %>을 사용하여 양식의 레이아웃을 제어하는 ​​것입니다. 이것은 양식이 어떻게 설계 되었기 때문입니다.Silverstripe : 사용자 지정 양식 서식 파일 - 유효성 검사 문제

(Template.ss)

<% control Form %> 
    <form class="wrap" $FormAttributes> 
     <% if $Message %> 
      <p id="{$FormName}_error" class="message $MessageType">$Message</p> 
     <% else %> 
      <p id="{$FormName}_error" class="message $MessageType" style="display: none"></p> 
      <% end_if %> 
      <fieldset> 
       <div class="member-details col lg-mobile-12 tablet-6 sm-desktop-6 md-desktop-6"> 
        <% if ModTest == 'false' %> 
         <div class="field wrap"> 
          <% control $Fields.dataFieldByName(ClientName) %> 
           <label class="title">$Title</label>$Field 
            <% end_control %> 
           </div> 
          <% end_if %> 
          <div class="field wrap"> 
           <% control $Fields.dataFieldByName(FirstName) %> 
            <label class="title">$Title</label>$Field 
           <% end_control %> 
          </div> 
          <div class="field wrap"> 
           <% control $Fields.dataFieldByName(Surname) %> 
            <label class="title">$Title</label>$Field 
           <% end_control %> 
          </div> 
          <% if $Fields.dataFieldByName(Address) %> 
           <div class="field address wrap"> 
            <% control $Fields.dataFieldByName(Address) %> 
             <label class="title">$Title</label> 
            <% end_control %> 
            <div class="address-fields wrap"> 
             $Fields.dataFieldByName(Address) 
             $Fields.dataFieldByName(Suburb) 
             $Fields.dataFieldByName(State) 
             $Fields.dataFieldByName(PostCode) 
            </div> 
           </div> 
          <% end_if %> 

          <% control $Fields.dataFieldByName(Phone) %> 
           <div class="field wrap"> 
             <label class="title">$Title</label>$Field 
           </div> 
          <% end_control %> 

          <% control $Fields.dataFieldByName(Email) %> 
           <div id="$HolderID" class="field wrap <% if $extraClass %> $extraClass<% end_if %>"> 
            <label class="title" for="$ID">$Title</label> 
            $Field 
            <% if $Message %><span class="message $MessageType">$Message</span><% end_if %> 
           </div> 
          <% end_control %> 

         </div> 
         <div class="password col lg-mobile-12 tablet-6 sm-desktop-6 md-desktop-6"> 
          <div class="field confirmedpassword"> 
           $Fields.dataFieldByName(Password)     
          </div> 
         </div> 
         $Fields.dataFieldByName(SecurityID) 
        </fieldset> 
        <div class="col lg-mobile-12 tablet-12 sm-desktop-12 md-desktop-12"> 
         <% if $Actions %> 
         <div class="Actions"> 
          <% loop $Actions %> 
           $Field 
          <% end_loop %> 
         </div> 
         <% end_if %> 
        </div> 
       </form> 
      <% end_control %> 

답변

1

템플릿에서 모든 양식 마크 업을 작성하면 - 실제로 양식 렌더링 및 템플릿의 목적을 거의 상실하게됩니다. 또한 새로 추가 된 필드를 양식에 추가하는 대신 템플리트 내에 추가해야하기 때문에 유연성이 매우 떨어집니다.

개인적으로 필드 (예 : 여러 필드를 줄 바꿈하는 필드)를 그룹화하고 사용자 지정 템플릿이 필요한 필드에 setTemplate을 사용하려면 개인적으로 CompositeField을 사용합니다.

사용자 정의 템플릿 및 합성 필드가있는 템플릿과 유사한 출력을 얻을 수 있어야한다고 생각합니다. 그래서 당신은 단지 $Form을 당신의 템플릿에 떨어 뜨리고 행복하게 될 것입니다. ...

+0

감사합니다. 나는 그것을 들여다 볼 것이다. – Dallby

1

당신이 필드 객체의 각 작업에 필요한 당 필드 레벨에서 메시지를 얻으려면 :

여기 내 코드입니다.

<% with $Fields.dataFieldByName(Name) %> 
    <div> 
     <label>Name</label> 
     <input name="Name" type="text" id="name" placeholder="Name" required> 
     <% if $Message %><span>$Message</span><% end_if %> 
    </div> 
<% end_with %> 

CSS 아이디의 다른 CMS 제어 텍스트를 추가하는 데 유용 분야에서 사용할 수 무엇을 나열합니다으로 내부 $Debug 추가.

+0

답장을 보내 주셔서 감사합니다. 위의 전자 메일 필드를 보면 오류가 발생하면 메시지가 출력됩니다. 그러나 실수를 수정하고 양식을 저장하면 데이터가 저장되지만 오류 메시지가 계속 나타나고 사라지지 않습니다. – Dallby