duanbicheng3345 2017-04-24 20:27
浏览 53

用if语句不能在php中显示div

I have a contact form, that passes input data to php. It works quite nice and shows messages when the email is wrong or the name not long enough by json. It also shows the response message if the email was sent or not by this.

    $send_mail = mail($to_email, $subject, $message_body, $headers);

    if(!$send_mail)
    {
        //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
        $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .' Achtung, es gab einen Fehler bei der Übertragung !'));
        die($output);
    }else{
        $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);
    }
}

I added these lines, in order to additionally show a div depending on email success or email fail with further informations. The divs are hidden at the start with document.ready {jquery.hide} and shall be shown by this code:

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

I just entered it right before the json encode array but this messes up the whole code.

This is how it looks now:

  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);
    }
}

Without these lines, it works just fine and shows all the messages as in the php file written inside a div with id="#contact_results". These lines not only don't show a additional div, they also stop the rest of the code, so the other messages also aren't displayed.

I'm not sure if this is enough information to solve my problem, if necessary i'll upload more code :)

Hope you can help me out :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题
    • ¥15 目标检测项目无法读取视频
    • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
    • ¥100 求采集电商背景音乐的方法