English 中文(简体)
提交未提交按钮
原标题:Submit button not submitting
<div class =  buttons >
 <button type="submit" class="regular" name="save">
        <img src="elephant.png" alt=""/>
        Memory
 </button>
</div>

这是提交按钮的代码

然而当我尝试使用php来验证窗体时, 按钮似乎没有提交

<?php if( isset($_POST[ save ]) && $_POST[ save ])
{
$submit = $_POST[ save ];
echo "lol";
}
else
{
echo "lola";

}
最佳回答

正如您已经写入的代码缺少包装。 将按钮作为按钮提交可能会在没有窗体的情况下有效, 但抓取 _POST 数据肯定不会成功 。

而且,你对图像按钮的解决方案可能更好, 也许像这样的东西:

<style type="text/css">
    input[type="submit"] {background: url( elephant.png ) right no-repeat; padding: 10px; padding-left: 30px; font-size: 14px; font-weight: bold;} /* or call this .regular */
</style>
<?
if ($_POST[ save ]) { // the trigger
    echo  <h1>Cooking with fire now!</h1> ;
}
?>
<form method="POST" action="">
    <div class="buttons">
        <input type="submit" name="save" value="Memory" class="regular" />
    </div>
</form>
  • Note that class = "buttons" with the spaces, is incorrect syntax!
问题回答

提交按钮只能在窗体中工作。 请尝试将整件事情以 < code> form 标签包起来, 然后再试一次 。

您的提交按钮在张贴窗体时没有任何值可发送 。 < 坚固> 元素 发送元素内容作为其提交值 。 您仍然需要在元素中添加一个 < code> value 属性, 以便使其 < em> 拥有 提交值 。 由于您没有, 它正在发送空字符串, 导致您有条件的语句失败 :

if( isset($_POST[ save ]) && $_POST[ save ])

由于 $_POST[ save] < is empty, 第二部分返回虚假, 因此会转到您的 else 块 。

这是您想要的代码 :

<form name="myForm" action="<?php echo $_SERVER[ PHP_SELF ]; ?>" method="post">
<div class="buttons">
 <button type="submit" class="regular" name="save" value="Save">
        <img src="elephant.png" alt="Elephant" />
        Memory
 </button>
</div>
</form>
  • You should include your code within <form method="post" action="path/to/your/php/processing/file"> and </form> tags
  • Replace your button code with <input type="submit" class="regular" name="save" />
  • Remove isset($_POST[ save ]) && part from condition of if as you don t have set value for your button.




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!