久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何檢查復(fù)選框是否在 PHP 中被選中?

How do I check if checkbox is checked in PHP?(如何檢查復(fù)選框是否在 PHP 中被選中?)
本文介紹了如何檢查復(fù)選框是否在 PHP 中被選中?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號..

我正在嘗試檢查是否已在 PHP 中選中復(fù)選框以進(jìn)行注冊.但它現(xiàn)在不起作用.這是我目前使用的代碼,用于檢查是否已被檢查.

if(!isset($_POST['tos']))$this->errors[] = '請接受我們的服務(wù)條款.';

這是 HTML 代碼.

<標(biāo)簽><input type="checkbox" name="tos" value="0">我同意<a href="#">服務(wù)條款</a>和<a href="#">隱私政策</a>

完整表格代碼:

 <form role="form" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>"><div class="form-group"><div class="row"><div class="col-sm-6"><label for="firstname">Firstname</label><input type="text" class="form-control" id="firstname" name="firstname" placeholder="Firstname">

<div class="col-sm-6"><label for="surname">Surname</label><input type="text" class="form-control" id="surname" name="surname" placeholder="Surname">

<div class="form-group"><label for="username">用戶名</label><input type="text" class="form-control" id="ruser" name="ruser" placeholder="用戶名">

<div class="form-group"><label for="email2">電子郵件地址</label><input type="email" class="form-control" id="remail" name="remail" placeholder="輸入電子郵件">

<div class="form-group"><div class="row"><div class="col-sm-6"><label for="password2">密碼</label><input type="password" class="form-control" id="rpass" name="rpass" placeholder="密碼">

<div class="col-sm-6"><label for="password2">重復(fù)密碼</label><input type="password" class="form-control" id="rpass2" name="rpass2" placeholder="密碼">

<div class="checkbox"><標(biāo)簽><input type="checkbox" name="tos" value="0">我同意<a href="#">服務(wù)條款</a>和<a href="#">隱私政策</a>

<input type="hidden" name="secur" value="<?php echo $ip;?>"/><input type="hidden" name="token" value="<?php echo $token;?"/><button type="submit" name="register" class="btn btn-block btn-color btn-xxl">創(chuàng)建賬戶</button></表單>

這段代碼有什么問題?任何幫助將不勝感激.

解決方案

if(!isset($_POST['tos']))$this->errors[] = '請接受我們的服務(wù)條款.';`

這是說如果 $_POST 中沒有tos",則拋出錯(cuò)誤.

你真的應(yīng)該用javascript檢查這個(gè)客戶端,表單被發(fā)送到服務(wù)器之前.

你也可以...

和 PHP:

if(isset($_POST['tos']) && $_POST['tos']==='accepted') echo 'All good';else array_push($errors,'此處的錯(cuò)誤代碼');//添加到$error數(shù)組

更新

我不確定您是否在使用 jQuery,但只是為了更用戶友好的方法:

var tos = $('#tos');var notice = $('.notice');tos.on('點(diǎn)擊',function(){if(tos.is(':checked')){notice.text('謝謝你.');}別的{notice.text('請接受我們的 ToS 以繼續(xù).');}})

在此處查看工作示例. 如果未選中,您甚至可以一起暫停表單.順便說一句,如果我沒記錯(cuò)的話 checkbox 輸入只發(fā)送 POST 數(shù)據(jù) if 選中.

I am trying to check if a checkbox have been checked in PHP in order to register. But it's not working right now. This is the code I am using so far, to check if it have been checked.

if(!isset($_POST['tos']))
  $this->errors[] = 'Please accept our Terms of Service.';

And this is the HTML code.

<div class="checkbox">
<label>
<input type="checkbox" name="tos" value="0"> I agree to the <a href="#">Terms of Service</a> and <a href="#">Privacy Policy</a>
</label>
</div>

Full form code:

        <form role="form" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
              <div class="form-group">

              <div class="row">
                  <div class="col-sm-6">
                  <label for="firstname">Firstname</label>
                  <input type="text" class="form-control" id="firstname" name="firstname" placeholder="Firstname">
                  </div>
                  <div class="col-sm-6">
                  <label for="surname">Surname</label>
                  <input type="text" class="form-control" id="surname" name="surname" placeholder="Surname">
                  </div>
              </div>
              </div>
              <div class="form-group">
                <label for="username">Username</label>
                <input type="text" class="form-control" id="ruser" name="ruser" placeholder="Username">
              </div>
              <div class="form-group">
                <label for="email2">Email address</label>
                <input type="email" class="form-control" id="remail" name="remail" placeholder="Enter email">
              </div>
              <div class="form-group">
                <div class="row">
                  <div class="col-sm-6">
                  <label for="password2">Password</label>
                  <input type="password" class="form-control" id="rpass" name="rpass" placeholder="Password">
                  </div>
                  <div class="col-sm-6">
                  <label for="password2">Repeat password</label>
                  <input type="password" class="form-control" id="rpass2" name="rpass2" placeholder="Password">
                  </div>
                </div>
              </div>
              <div class="checkbox">
                <label>
                  <input type="checkbox" name="tos" value="0"> I agree to the <a href="#">Terms of Service</a> and <a href="#">Privacy Policy</a>
                </label>
              </div>
               <input type="hidden" name="secur" value="<?php echo $ip;?>"/>
               <input type="hidden" name="token" value="<?php echo $token;?>"/>
              <button type="submit" name="register" class="btn btn-block btn-color btn-xxl">Create an account</button>
            </form>

What's wrong with this code? Any help would be appreciated.

解決方案

if(!isset($_POST['tos']))
  $this->errors[] = 'Please accept our Terms of Service.';`

What this is doing is saying if there is no 'tos' in $_POST, throw an error.

Really you should probably check this client side with javascript, before the form is sent to the server.

You could also...

<input type="checkbox" name="tos" value="accepted" checked>

And PHP:

if(isset($_POST['tos']) && $_POST['tos']==='accepted') echo 'All good'; 
else array_push($errors,'err code here'); //to add to $error array

Update

I'm not sure if you're using jQuery or not, but just for a more user friendly approach:

var tos = $('#tos');
var notice = $('.notice');
tos.on('click',function(){
  if(tos.is(':checked')){
    notice.text('Thank you.');
  }
  else{
   notice.text('Please accept our ToS to continue.');
  }
})

See a working example here. You could even halt the form all together if it's unchecked. BTW, if I remember correctly checkbox inputs only send POST data if checked.

這篇關(guān)于如何檢查復(fù)選框是否在 PHP 中被選中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗(yàn)證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產(chǎn)品中添加一個(gè)將更改價(jià)格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 亚洲欧美精品国产一级在线 | 在线国产视频 | 亚洲欧美另类在线观看 | 欧美日韩综合一区 | 亚洲品质自拍视频网站 | 在线观看国产www | 国产乱码精品一区二区三区中文 | 午夜一区二区三区在线观看 | 精品久久久久久亚洲综合网 | 日本小视频网站 | 国产在线视频一区 | 亚洲精品九九 | 亚洲av毛片成人精品 | 午夜伦理影院 | 国产欧美一级 | 国产精品不卡视频 | 午夜精品视频在线观看 | 九九热在线视频 | 久久久精品日本 | 色999视频| 成人国产精品久久久 | 国产精品久久av | 欧美激情一区二区 | 91精品国产91久久久久游泳池 | 国产精品视频观看 | 国产精品亚洲精品日韩已方 | 天堂资源最新在线 | 国产综合视频 | 国产精品久久久久久久久久免费看 | 欧美一区二区三区在线观看视频 | hitomi一区二区三区精品 | 亚洲a人| 91亚洲欧美 | 成人婷婷| 欧美a∨| 亚洲欧美国产精品一区二区 | 久久噜| 在线欧美亚洲 | 九九国产| 一区二区视频在线观看 | 国产精品视频不卡 |