无法在php中使用if语句显示div

时间:2017-04-24 20:27:41

标签: javascript php jquery html

我有一个联系表单,将输入数据传递给php。 它工作得很好,当电子邮件错误或json的名称不够长时显示消息。如果电子邮件是由此发送的,它还会显示响应消息。

   ?>
      <script type="text/javascript">$('#alertz').show()</script>
   <?php
 ?>
      <script type="text/javascript">$('#successss').show()</script>
   <?php

我添加了这些行,以便另外显示div取决于电子邮件成功或电子邮件失败以及更多信息。这些div在文本开头用document.ready {jquery.hide}隐藏,并且应该由以下代码显示:

  if(!$send_mail)
    {
        //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
        ?>
        <script type="text/javascript">$('#alertz').show()</script>
        <?php
        $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .' Achtung, es gab einen Fehler bei der Übertragung !'));
        die($output);
    }else{
        ?>
        <script type="text/javascript">$('#successss').show()</script>
        <?php
        $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .' Vielen Dank für Ihre Anfrage. Wir prüfen diese umgehend und geben Ihnen schnellstmöglich eine Antwort'));

        die($output);
    }
}

我刚刚在json编码数组之前输入它,但这会弄乱整个代码。

现在的样子:

<fo:block font-size="10" background-color="#000000" color="#ffffff">DEPARTURE</fo:block>

如果没有这些行,它就可以正常运行并显示所有消息,如在php文件中写入id =&#34;#contact_results&#34;的div中。这些行不仅不会显示额外的div,还会停止其余的代码,因此其他消息也不会显示。

我不确定这是否足以解决我的问题,如有必要,我会上传更多代码:)

希望你能帮帮我:)。

0 个答案:

没有答案