1

我正在尝试将 Recaptcha 实施到 Silverstripe,一切运行良好,但是当验证码信息未填写时,强制消息“请回答验证码问题”不会仅显示在我的一张表格上。

谁能给我一些关于如何解决这个问题的指导?多谢了。

这是我在按照步骤安装并安装了recaptcha 和spamprotection 之后所做的。

我在 BookingFormPage.php 中添加了新的 RecaptchaField('MyCaptcha')

$fields = new FieldSet(
        $TourDropDown, 
        new TextField('FirstName'),
        new TextField('LastName'),
        new TextField('EmailAddress')
        new DropdownField('People','People Travelling',$People),
        new DropdownField('Accommodation','Accommodation Standard',$Accommodation),
        new DropdownField('Rooms','How Many Rooms',$Rooms),
        new DropdownField('Transport','Transport Option',$Transport),
        new DropdownField('TransportSelfDrive','If self drive select grade',$TransportSelfDrive),
        new TextField('FlightArrival','Flight Arrival Details'),
        new TextField('FlightDeparture','Flight Departure Details'),
        new DropdownField('LengthOfStay','Length of stay',$LengthOfStay),
        new TextareaField('Comments'),
        **new RecaptchaField('MyCaptcha')**

    );

and I added 

<div class="formHoizontal">
<div id="MyCaptcha" class="field recaptcha ">
$dataFieldByName(MyCaptcha) 
</div>
</div>

to the BookingForm.ss

<form $FormAttributes class="threecolumnform">
<% 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="formHoizontal">
        <div class="field text">
            <label class="left" for="$FormName_Tour">Tour</label>
            $dataFieldByName(Tour)
        </div>
    </div>
    <div class="clear"></div>
    <div class="formHoizontal">
        <div id="FirstName" class="field text">
            <label class="left" for="$FormName_FirstName">First name</label>
            $dataFieldByName(FirstName)
        </div>
        <div>
            <label class="left" for="$FormName_LastName">Last name</label>
            $dataFieldByName(LastName)
        </div>
    </div>
    <div class="clear"></div>
    <div class="formHoizontal">
        <div id="EmailAddress" class="field email">
            <label class="left" for="$FormName_EmailAddress">Email</label>
            $dataFieldByName(EmailAddress)
        </div>

    </div>
    <div class="clear"></div>
    <div class="formHoizontal">

        <div class="field text">
            <label class="left" for="$FormName_LengthOfStay">Length of stay</label>
            $dataFieldByName(LengthOfStay)
        </div>
    </div>
    <div class="clear"></div>


    <div class="formHoizontal">
        <div class="field text">
            <label class="left" for="$FormName_People">Number of Adults</label>
            $dataFieldByName(People)
        </div>


    </div>


    <div class="clear"></div>
    <br />
    <h4>Accommodation</h4>
    <div class="formHoizontal">
        <div class="field text">
            <label class="left" for="$FormName_Accomadation">Type</label>
            $dataFieldByName(Accommodation)
        </div>
        <div class="field text">
            <label class="left" for="$FormName_Rooms">Number of rooms</label>
            $dataFieldByName(Rooms)
        </div>
        <div class="field text">
            <label class="left" for="$FormName_RoomConfig">Room requirements</label>
            $dataFieldByName(RoomConfig)
        </div>
    </div>


    <div class="clear"></div>
    <br />
    <h4>Transport</h4>
    <div class="formHoizontal">
        <div class="field text">
            <label class="left" for="$FormName_Transport">Type</label>
            $dataFieldByName(Transport)
        </div>

        <div>
            <label class="left" for="$FormName_TransportSelfDrive">If self drive select grade</label>
            $dataFieldByName(TransportSelfDrive)
        </div>
        <div class="clear"></div>
    </div>


    <div class="clear"></div>
        <div>
            <div class="field text">
                <label class="left" for="$FormName_SightSeeing">Enter any sightseeing or activities you would like included</label>
                $dataFieldByName(SightSeeing)
            </div>
        <div><h4>Sightseeing</h4></div>
        </div>
    <br />

    <div class="formHoizontal">
        <div class="field text">
            <label class="left" for="$FormName_FlightArrival">Flight Arrival Details</label>
            $dataFieldByName(FlightArrival)
        </div>
        <div class="field text">
            <label class="left" for="$FormName_FlightDeparture">Flight Departure Details</label>
            $dataFieldByName(FlightDeparture)
        </div>
    </div>

    <div class="clear"></div>
    <br /><br /><br />


        **<div class="formHoizontal">
        <div id="MyCaptcha" class="field recaptcha ">
            $dataFieldByName(MyCaptcha)

    </div>
    </div>**


    <div class="clear"></div>
    <br /><br /><br />



    <div class="formHoizontalTwoColumn">

        <div class="field text">
            <label class="left" for="$FormName_Comments">Extra Information</label>
            $dataFieldByName(Comments)
        </div>
    </div>


  $dataFieldByName(SecurityID)

非常感谢。

亲切的问候山姆

4

1 回答 1

1

当验证码信息未填写时,强制消息“请回答验证码问题”不会仅显示在我的一张表格上

你的意思是它根本没有显示或显示多次?

我的模板看起来像这样(包括 CSS 网格等) - 应该显示错误消息:

<div class="push_2 grid_15 formbackground">
    <div class="grid_4">
        <label for="recaptcha_response_field" class="right">Captcha*<br/><span>Bitte die Zeichen der Grafik in das Feld eingeben</span></label>
    </div>
    <div class="grid_9">
        $dataFieldByName(MyCaptcha)
        <span class="message $dataFieldByName(MyCaptcha).MessageType">$dataFieldByName(MyCaptcha).Message</span>
    </div>
</div>

这有帮助吗?

于 2011-12-06T14:05:03.330 回答