【问题标题】:Zend get value from textbox and add it into search urlZend 从文本框中获取值并将其添加到搜索 url
【发布时间】:2013-01-11 02:37:16
【问题描述】:

我有问题,这是以下代码。

<form action="" method="post" id="search">
        <div class="row collapse">
        <div class="ten columns mobile-three">
        <input type="text" size="25" name="search" value="<?php echo $this->search ?>"/>
        </div>
        <div class="two columns mobile-three">
        <input type="submit" name="/search/index/keyword/" value="Search"; ?>" class="button   expand postfix" id="search_button"/> 
        </div>
        </div>
</form>

当我点击提交按钮时,网址应该是 从id/id/search/index/keyword/(here's the search key)

【问题讨论】:

    标签: php html zend-framework search


    【解决方案1】:

    HTML

    <form action="" method="post" id="search" name="search" onsubmit="submitForm();">
            <div class="row collapse">
            <div class="ten columns mobile-three">
            <input type="text" size="25" name="search" id="search_value" value="<?php echo $this->search ?>"/>
            </div>
            <div class="two columns mobile-three">
            <input type="hidden" value="/search/index/keyword/" id="search_url"/> 
            <input type="submit" name="search" class="button   expand postfix" id="search_button"/> 
            </div>
            </div>
    </form>
    

    JS

    <script>
        function submitForm() 
        {
            var search_button = document.getElementById('search_url').value;
            var search_text = document.getElementById('search_value').value;
            document.searchForm.action = search_button + '/' + search_text;
            document.searchForm.submit();
            return false;
        }
    
    </script>
    

    PHP

    <?php
    
    if (isset($_POST['search'])) {
        // add action code here
    }
    
    ?>
    

    【讨论】:

    • 从没想过它会使用 javascript,我在 javascript 方面还不够好。但是这个是可行的,我只需要更改 url。谢谢
    • JS中不应该使用document.searchForm这种形式的name="searchForm"
    【解决方案2】:

    我会为此使用服务器端语言。制作流程页面(除非您熟悉 AJAX),通过 $_POST 获取值并重定向流程页面。

    我很确定也可以使用 JavaScript,但我真的不擅长,所以不要指望我的解决方案。

    【讨论】:

      【解决方案3】:

      您可以使用 JS 来实现您的目标。

      1) 创建一个在用户点击提交按钮时运行的函数。

      2) 函数从搜索框中抓取单词。

      3) 函数改变表单元素的“action”属性

      4) 表单提交

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-31
        • 2022-01-11
        相关资源
        最近更新 更多