Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果设置了,则仅通过获取信息_Php_Html_Forms - Fatal编程技术网

Php 如果设置了,则仅通过获取信息

Php 如果设置了,则仅通过获取信息,php,html,forms,Php,Html,Forms,我正在使用一个带有GET方法的表单来添加到查询字符串中 我遇到了一个问题。提交表单时,每个字段都会被发送并添加到查询中,包括没有值的字段 例如: http://web.com/?filter-types=news&filter-document-type=&filter-topics=we-have-a-topic&filter-featured=&filter-rating= 如果没有设置,我可以不将它们添加到查询字符串中吗!isset()或者是否有其他方法可

我正在使用一个带有GET方法的表单来添加到查询字符串中

我遇到了一个问题。提交表单时,每个字段都会被发送并添加到查询中,包括没有值的字段

例如:

http://web.com/?filter-types=news&filter-document-type=&filter-topics=we-have-a-topic&filter-featured=&filter-rating=

如果没有设置,我可以不将它们添加到查询字符串中吗<代码>!isset()或者是否有其他方法可以做到这一点

所有这些键出现在查询字符串中的原因是它们作为表单中的输入存在。如果您不想发送,请将其从表单中删除,或者至少提供一些有意义的默认值。

您也可以通过javascript操作表单输入,正如Mike在评论中所说,在提交时检查字段,如果字段为空,请禁用它们,以便在提交时不包含它们

这只是基本思想(使用jQuery):





$('input[name=“submit_form”]”)。在('click',函数(e){ e、 预防默认值(); $('form').children().each(函数(i,e){ if($(e).is('input')&&$(this.val()=''){ $(this.prop('disabled',true); //或$(this.attr('name',''); } }); $('form').submit(); });
或者,如果您根本不想使用jquery:

document.getElementById('submit_form').addEventListener('click', function(e){
    e.preventDefault();
    var children = document.getElementById('form_inputs').childNodes;
    for(i = 0; i < children.length; i++) {
        if(children[i].type == 'text' && children[i].value == '') {
            children[i].disabled = true;
        }
    }
    document.getElementById('form_inputs').submit();
});
document.getElementById('submit_form')。addEventListener('click',函数(e){
e、 预防默认值();
var children=document.getElementById('form_inputs').childNodes;
对于(i=0;i
我想你正在寻找一种状态

 if (!empty($_POST['var'])) {

 }


你为什么喜欢这个?您希望如何处理下一页上的数据?您可以向onSubmit事件添加Javascript处理程序,并在提交表单之前使用它禁用任何空字段。未提交禁用的字段。
 if (!empty($_POST['var'])) {

 }
 if (!isset($_POST['var']) && !empty($_POST['var'])) {

 }