简体   繁体   English

仅以php形式提交填充字段

[英]Submit only filled fields in form php

I have a basic form with a lot of input text boxes to fill: 我有一个基本表单,其中包含很多输入文本框:

<form action="page2.php" method="get">
<input type="text" name="a">
<input type="text" name="b">
...
<<input type="text" name="z">>
</form>

I want to pass to page2.php only filled input fields and ignore the rest. 我只想传递给page2.php填充的输入字段,而忽略其余的输入字段。 It seems simple but i can't figure it out... 看起来很简单,但我不知道...

Thanks! 谢谢!

It's much easier to filter out the empty fields on page2.php: 过滤掉page2.php中的空字段要容易得多:

$_GET = array_filter($_GET);

That removes any empty $_GET array entries. 这将删除所有空的$_GET数组条目。

If you absolutely have to do this before submitting to page2, you'll need to use client-side javascript to loop through all form fields and remove the ones that are empty. 如果绝对必须在提交到page2之前执行此操作,则需要使用客户端javascript遍历所有表单字段并删除空字段。 Not ideal. 不理想。

In page2.php 在page2.php中

use 采用

foreach($_GET as $key => $value){
// This will extract those fields which dint have value.
}

Alternatively you can use jQuery / Javascript to iterate over input type text and send only those fields which have values in it. 另外,您可以使用jQuery / Javascript遍历输入类型的文本,并仅发送其中包含值的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM