簡體   English   中英

是否有可能以php形式從文本框接受多個輸入?

[英]Is it possible to take more than one input from a textbox in a php form?

我試圖用php代碼制作一個計算器程序。

我是使用html和javascript編寫的,但有人告訴我將php代碼用作邏輯部分。

有什么方法可以以php形式從文本框中獲取多個輸入?

是的,您可以通過為它們提供不同的名稱並通過$_REQUEST['input_name']訪問它們來輕松地使用表單中的多個輸入。

在此示例中,我正在做的是從彈出窗口中獲取選中的復選框,並將其作為逗號分隔的列表放入主窗體的文本輸入字段中。

的HTML

<input type="text" id="entry-r1" placeholder="place" tabindex="1">
    <a class="show-lookup button" href="#" id="popup-r1" tabindex="2"><i class="fa fa-search"></i></a>
    <div class="overlay">&nbsp;</div>
    <div class="lookup-multiselect" id="lookup-r1">
        <a class="button close-button right">x</a>
        <form action="" id="form-r1" name="form-r1" method="post">
            <input class="checkall" id="checkall" type="checkbox">
        <label for="checkall" class="narrow">Select all</label>
            <p class="category" id="checkboxes-r1"><strong>Select...</strong><br>
                <input class="js-popup-focus" type="checkbox" name="place" id="antwerp" value="Antwerp" tabindex="3"> <label for="antwerp">Antwerp</label><br>
                <input type="checkbox" name="place" id="berlin" value="Berlin" tabindex="3"> <label for="berlin">Berlin</label><br>
                <input type="checkbox" name="place" id="cairo" value="Cairo" tabindex="3"> <label for="cairo">Cairo</label><br>
                <input type="checkbox" name="place" id="duss" value="D&uuml;sseldorf" tabindex="3"> <label for="duss">D&uuml;sseldorf</label><br>
            </p>
        </form>
            <a href="#" class="button close-button right" tabindex="4">Use selected</a>
    </div>

的CSS

.overlay {
    display: none;
    position: fixed;
    text-align: center;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.7;
    background: #333;
}

.lookup-popup, .lookup-multiselect {
    padding: 0.5em;
    display: none;
    z-index: 99999;
    background-color: #fff;
    position: absolute;
    top: 5em;
    left: 25%;
    width: 20%;
}

jQuery的

 $(document).ready(function () 
{   

    /* get id of form to work with */

    $('.show-lookup').click(function()
    {
        var pairedId = $(this).attr('id').split('-');
        var lookupToDisplay = '#lookup-' + pairedId[1];
        $('.overlay').show();
        $(lookupToDisplay).show();
        $('.js-popup-focus').focus();
    });

/* put value selected in lookup into field in main form */

    $('.lookup-popup input').on('change', function() 
    {  
        var fieldname = $(this).attr('name');
        var pairedId = $(this).parent().attr('id').split('-');
        var selOption = $('input[name='+fieldname+']:checked').val(); 
        $("#entry-"+pairedId[1]).val(selOption);
    });

/* for checkbox version, append selected values to field in main form */    

    $('.lookup-multiselect input').on('change', function() 
    {  
        var pairedId = $(this).parent().attr('id').split('-');
        //event.preventDefault();
        var selOptions = $(".category input:checkbox:checked").map(function(){
          return $(this).val();
        }).get(); // <----
        //console.log(selOptions);
        var selectedString = selOptions.toString();
        $("#entry-"+pairedId[1]).val(selOptions);
    });

    $('.close-button').click(function()
    {
        $(this).parent().hide();
        var pairedId = $(this).parent().attr('id').split('-');
        $('.overlay').hide();
        $("#entry-"+pairedId[1]).focus();
    });
});

暫無
暫無

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

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