【问题标题】:Submit Button only when no value present in field otherwise value shows仅当字段中不存在值时才提交按钮,否则显示值
【发布时间】:2015-05-12 21:05:06
【问题描述】:

我试图弄清楚如何让这段代码 sn-p 显示值或按钮,但不能同时显示两者。如您所见,有一个“Call_Attempt_One”按钮。我试图让它仅在字段中没有值时显示,但在有值时显示字段值并让按钮消失。

建议??谢谢!

<td style='font-size:12px;width:500px;'><div style=\"overflow-x:auto; max-height:100px\">{$row['Project_Description']}</div></td>
<td style='font-size:12px;'><center>{$row['Restoration_Decision_Matrix']}</center></td>
<td style='font-size:12px;'><center>

    <form action='".$_SERVER['PHP_SELF']."' method='post'>
    <input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
    <input type='submit' name='formCalledOne' id='formCalledOne' value='Called' />
    </form>
{$row['Call_Attempt_One']}

</center></td>
<td style='font-size:12px;'><center><button type=\"submit\" form=\"form1\" value=\"Submit\">Called</button></center></td>
<td style='font-size:12px;'><center><button type=\"submit\" form=\"form1\" value=\"Submit\">Called</button></center></td>
<td style='font-size:12px;'><center><button type=\"submit\" form=\"form1\" value=\"Submit\">Emailed</button></center></td>
<td style='font-size:12px;'><center>Text Area</center></td>
<td style='font-size:12px;'><center>{$row['Received_Date']}</center></td>
<td style='font-size:12px;'><center>

    <form action='".$_SERVER['PHP_SELF']."' method='post'>
    <input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
    <input type='submit' name='formDelete' id='formDelete' value='Delete' />
    </form>


</center></td>
</tr>";

}

//Check to see if delete button is pressed
if(isset($_POST['formDelete']))
{
    if(isset($_POST['ID']) && !empty($_POST['ID']))
    {
        $ID = $_POST['ID'];
        $result = mysql_query("DELETE FROM Project_Submissions WHERE ID ='".$ID."'");
    }
}   

【问题讨论】:

  • 请澄清一下您所说的“当没有价值时”您指的是哪个价值?
  • 当然,我的意思是在伪代码中,如果数据库中的 callattemptone 字段是空的显示按钮。如果 callattemptone 字段已经有值显示该值而不是按钮
  • 使用以下条件 if($row['Call_Attempt_One'] ==""){// 显示按钮代码}else{//echo $row['Call_Attempt_One']} 为空请阅读此stackoverflow.com/questions/8236354/php-is-null-or-empty

标签: php forms submit


【解决方案1】:

这是我在上面的问题中发现的代码。我自己修复并替换了这些行

if(isset($_POST['formDelete']))
{
    if(isset($_POST['ID']) && !empty($_POST['ID']))
    {
        $deleteID = $_POST['ID'];
        $result = mysql_query("DELETE FROM Project_Submissions WHERE ID ='".$deleteID."'");
    }
}   

【讨论】:

  • 虽然这可能会回答这个问题,但在您的答案中加入一些文字来解释您在做什么总是一个好主意。阅读how to write a good answer
  • 这与答案无关
猜你喜欢
  • 2019-06-04
  • 2017-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多