dopnpoh056622 2014-08-28 01:11
浏览 55
已采纳

获取Bootstrap按钮的活动状态并作为表单php的一部分提交

I am using several buttons on my page of the same class. Here is an example:

<button id="YES" type="button" class="btn btn-lg btn-primary" data-toggle="button" name="yesPowerwash">YES</button>

I believe I can determine whether or not the button has been toggled with the following (please correct me if I am wrong):

 $('[name="noPowerwash"]').hasClass('active') 

I cannot figure out how to post the state (active vs inactive) as part of the form submission.

Any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • doutenggu4070 2014-08-28 17:40
    关注

    This is just part of the value field in bootstrap. i.e This is an example for a radio button you can change it to a regular button by just looking at the documentation here.

     <label class="radio-inline">
              <input type="radio" id="buycheckbox" value="buy" name="radiogroup" required>Buy
     </label>
    

    So the value here is buy. Where ever you post too, let's say another php page you can check to see if the radiogroup button was clicked as buy. i.e

    if($_POST['radiogroup'] == 'buy')
    

    Your html:

      <form id="contact-form" method="POST" action="form-handling.php">
                  <div class="success"> Contact form submitted! <strong>We will be in touch soon.</strong> </div>
                  <fieldset>
                <div>
                    <label class="name">
                    <input type="text" value="name">
                    <br>
                    <span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span> </label>
                    </div>
                <div>
                    <label class="phone">
                    <input type="tel" value="Telephone">
                    <br>
                    <span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span> </label>
                    </div>
                <div>
                    <label class="email">
                    <input type="email" value="Email">
                    <br>
                    <span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span> </label>
                    </div>
                <div>
                    <label class="message">
                    <textarea>Message</textarea>
                    <br>
                    <span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>
                    </div>
                <div class="buttons-wrapper"> <a class="btn btn-1" data-type="reset">Clear</a> <a class="btn btn-1" data-type="submit">Send</a></div>
              </fieldset>
                </form>
    

    form-handling.php

    name  =$_POST['name'];
    tele = $_POST['Telephone']
    ..... etc
    

    Now just add the button label/input to the form

    Try this to do the toggleing its just another example.

    It doesn't matter if the type = radio or check box its the div that gives the look.

        <div class="btn-group" data-toggle="buttons">
            <label class="btn btn-default">
                <input name="year" value="2011" type="radio">2011
            </label>
            <label class="btn btn-default">
                <input name="year" value="2012" type="radio">2012
            </label>
            <label class="btn btn-default">
                <input name="year" value="2013" checked="" type="radio">2013
            </label>
      </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题