为什么我的输入不能与Get方法一起使用?
问题描述:
因为我在一个WordPress网站上工作,所以在WordPress堆栈交换网站上发布了这一篇,但我认为这是一个更好的问题。为什么我的输入不能与Get方法一起使用?
我有我想为同一形式的一部分使用两个输入。他们两个都完美地向url栏提供$ _GET,但只在他们单独工作时。当两者都在页面上时,输入任一值并按回车键都不会执行任何操作。
<form action="<?php the_permalink() ?>" method="get">
<?php
/* receiveGET() is just a function I wrote that grabs the $_GET results */
$inst = receiveGET(instrument_search);
$search_field = receiveGET(user_search);
/* all the form processing stuff goes here, and it's all working properly */
?>
<!-- If this input is deleted, the other input works perfectly. -->
<table id="musician-field" class="form-table">
<tr>
<td>
<input title="Search User" name="user_search" maxlength="21" placeholder="Search Name" value="<?php echo htmlspecialchars($_GET[user_search]); ?>" ></input>
</td>
</tr>
</table>
<!-- If this input is deleted, the other input works perfectly. -->
<table id="instrument-field" class="form-table">
<tr>
<td>
<input title="Search Instrument" name="instrument_search" maxlength="21" placeholder="Search Instrument" value="<?php echo htmlspecialchars($_GET[instrument_search]); ?>" ></input>
</td>
</tr>
</table>
/* The form close tab is way below a lot of PHP and HTML,
but I have the same bug happen when I move it up to be
directly enclosing the inputs */
</form>
我知道所有的变量都在经历正常,所以我敢肯定这是从我的形式是如何工作的理解不够而产生的,但我想不出是什么问题。我在网上看到的所有内容似乎都限制了表单输入的数量。任何人都在照顾我,并知道如何解决这个问题?
谢谢!
答
好几件事情。
- 我刚刚测试了您的代码,并且获取了
user_search
和instrument_search
的未定义索引错误。所以我试着在它们之前做一个isset函数,它对我很有用。 - 你忘了把单引号
$_GET['user_search']
和$_GET['instrument_search']
。
试试下面的代码在你的价值观:
<?php echo isset($_GET['user_search']) ? htmlspecialchars($_GET['user_search']) : ' '; ?>
和
<?php echo isset($_GET['instrument_search']) ? htmlspecialchars($_GET['instrument_search']) : ' '; ?>
什么是你无论如何在投入使用值标签的目的是什么?你可以在你的php中使用$ _GET,并且不用价值标签就可以得到这些值。使用value=
将覆盖您的占位符,并且输入框在加载页面时将不显示任何文本!
只是吐成球,但你可以尝试改变你的方法来发布,看看结果是否相同 – Rager
我没有看到一个PHP结束标签'?>'后你的PHP ..可能会搞乱你的表格数据 – Rager
嘿Klynicol。当我最初发布问题并忘记了PHP标记时,我搞砸了。固定。谢谢。 此外,我只是尝试用POST并得到完全相同的结果。 =( – MarvinLazer