簡體   English   中英

php電話驗證不起作用

[英]Php phone validation doesn't work

我正在使用Prestashop 1.6,不是很喜歡PHP,但是我想對網站外觀進行1處更改。 默認情況下,我有2個電話輸入:用於家庭和移動電話。 看起來像這樣:

<div style="display: none" class="form-group is_customer_param">
                    <label for="phone">{l s='Home phone'}{if isset($one_phone_at_least) && $one_phone_at_least} <sup>**</sup>{/if}</label>
                    <input type="text" class="text form-control validate" name="phone" id="phone" data-validate="isPhoneNumber" value="{if isset($guestInformations) && isset($guestInformations.phone) && $guestInformations.phone}{$guestInformations.phone}{/if}" />
                </div>
                <div class="{if isset($one_phone_at_least) && $one_phone_at_least}required {/if}form-group">
                    <label for="phone_mobile">{l s='Mobile phone'}{if isset($one_phone_at_least) && $one_phone_at_least} <sup>*</sup>{/if}</label>
                    <input type="text" class="text form-control validate" name="phone_mobile" id="phone_mobile" data-validate="isPhoneNumber" value="{if isset($guestInformations) && isset($guestInformations.phone_mobile) && $guestInformations.phone_mobile}{$guestInformations.phone_mobile}{/if}" />
                </div>
                {if isset($one_phone_at_least) && $one_phone_at_least}
                    {assign var="atLeastOneExists" value=true}
                    <p class="inline-infos required">* Podaj nr telefonu</p>
                {/if}

我已經使第一個不可見,因為我認為一個填充字段就足夠了。 而且似乎是。 但是我可以提交表格而無需輸入手機號碼。 您看到這里可能有問題嗎? 或者,也許我該如何運作?

確實需要工作原理很好的字段示例,並且未與其他字段配對:

    <div class="required form-group">
                        <label for="lastname_invoice">{l s='Last name'} <sup>*</sup></label>
                        <input type="text" class="form-control validate" id="lastname_invoice" name="lastname_invoice" data-validate="isName" value="{if isset($guestInformations) && isset($guestInformations.lastname_invoice) && $guestInformations.lastname_invoice}{$guestInformations.lastname_invoice}{/if}" />
                    </div>

我嘗試通過以下方式驗證移動設備:

<div class="required phone_mobile form-group">
                    <label for="phone_mobile">{l s='Mobile phone'} <sup>*</sup></label>
                    <input type="text" class="text form-control validate" name="phone_mobile" id="phone_mobile" data-validate="isPhoneNumber" value="{if isset($guestInformations) && isset($guestInformations.phone_mobile) && $guestInformations.phone_mobile}{$guestInformations.phone_mobile}{/if}" />
                </div>

但沒有成功...

看來$one_phone_at_least變量未設置為true 從后台轉到“首選項” >“ 客戶” ,並確保已打開“電話號碼為必填項”。 那應該解決它。

順便說一句,應該在input而不是form-group容器上使用required類。 如果進行了更改,則可以阻止用戶提交該表單,但是如果他們解決該表單以發送沒有電話號碼的數據,則服務器將允許它。 通過執行第一段中的步驟,服務器還將要求設置電話號碼。

在函數“ postProcess()”中打開controllers / front / ContactController.php

您可以輸入發出該消息並發布的必填字段

使必修電話號碼發生變化

否則,必須將電話號碼添加到列表中,否則:

} elseif (!(Tools::getValue('phone_mobile')||Tools::getValue('phone'))) {
            $this->errors[] = Tools::displayError('It is mandatory to enter a pleasant phone number.');
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM