Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除iframe后,联系人表单在浏览器中显示PHP_Php_Iframe_Contact Form - Fatal编程技术网

删除iframe后,联系人表单在浏览器中显示PHP

删除iframe后,联系人表单在浏览器中显示PHP,php,iframe,contact-form,Php,Iframe,Contact Form,我想重用/重新设计一个我以前使用过的php表单,但是使用了一个调用php文件的iframe。我被告知这是一种不好的做法,并停止使用iFrame;但是,当我将php移动到html页面时,php代码显示在表单的文本字段中 我在这里检查了几页的php线程,似乎问题通常是忘记关闭php标记或者主机不支持php。我没有改变php本身的工作版本,我的主机支持php版本5.3.6 编辑:将文件更改为.php清除了浏览器中的php,但表单不会发送 文本字段中显示的PHP如下所示: <?php echo (

我想重用/重新设计一个我以前使用过的php表单,但是使用了一个调用php文件的iframe。我被告知这是一种不好的做法,并停止使用iFrame;但是,当我将php移动到html页面时,php代码显示在表单的文本字段中

我在这里检查了几页的php线程,似乎问题通常是忘记关闭php标记或者主机不支持php。我没有改变php本身的工作版本,我的主机支持php版本5.3.6

编辑:将文件更改为.php清除了浏览器中的php,但表单不会发送

文本字段中显示的PHP如下所示:

<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['name'] : '' ?>
<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['email'] : '' ?>
<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['message'] : '' ?>

Contact.html页面代码:

    <div id="contact-form" class="clearfix">

<?php session_start(); ?>
<?php
include("spam_check.php");
?>
            <h2> You can contact us by filling out the form below.</h2>
            <?php
            //init variables
            $cf = array();
            $sr = false;

            if(isset($_SESSION['cf_returndata'])){
                $cf = $_SESSION['cf_returndata'];
                $sr = true;
            }
            ?>
            <ul id="errors" class="<?php echo ($sr && !$cf['form_ok']) ? 'visible' : ''; ?>">
                <li id="info">There were some problems with your form submission:</li>
                <?php 
                if(isset($cf['errors']) && count($cf['errors']) > 0) :
                    foreach($cf['errors'] as $error) :
                ?>
                <li><?php echo $error ?></li>
                <?php
                    endforeach;
                endif;
                ?>
<?php
if (isset($_POST['real'])) {
  // error condition, redisplay form
}
?>
            </ul>
            <p id="success" class="<?php echo ($sr && $cf['form_ok']) ? 'visible' : ''; ?>">Thanks for your message! We will get back to you ASAP!</p>
            <form method="post" action="process.php">
                <label for="name">Name: <span class="required">*</span></label>
                <input type="text" id="name" name="name" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['name'] : '' ?>" placeholder="Your Name" required autofocus />

                <label for="email">Email: <span class="required">*</span></label>
                <input type="email" id="email" name="email" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['email'] : '' ?>" placeholder="yourname@example.com" required />

                <label for="message">Message: <span class="required">*</span></label>
                <textarea id="message" name="message" placeholder="Your message must be greater than 20 characters." required data-minlength="20"><?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['message'] : '' ?></textarea>

<label style="display:block;position:absolute;left:-9999px" class="real">
  Please leave this checkbox blank
  <input type=checkbox name=real value=1>
</label>

                <span id="loading"></span>
                <input type="submit" value="SEND" id="submit-button" />
                <p id="req-field-desc"><span class="required">*</span> indicates a required field</p>          
            </form>

            <?php unset($_SESSION['cf_returndata']); ?>
        </div>

您可以通过填写下表与我们联系。

查看页面源代码-其他PHP代码也在那里吗?如果php不能正常工作,那么所有的代码都会显示出来,而不仅仅是表单字段中的一些位


你说你把它移到了一个“html文件”。那是“somefile.html”吗?请记住,Web服务器通常不会将.html设置为由PHP解析。尝试将其重命名为“somefile.php”。

是的,我可以查看源代码中的所有php。我将文件改为.php,现在看起来一切都很好,尽管我发了一封从未收到的测试电子邮件。我最初搜索是为了看看在html页面中植入php是否合适。我遇到的结果只是简单地说总是包括我在开始时仍然调用html doctype有关系吗?与doctype无关,一切都与Web服务器不会通过PHP解释器传递.html文件这一事实有关,除非您告诉它。好的。我只是想弄明白为什么表单现在显示正确,但不会提交。在原始帖子中添加了Process.php。我想知道我是否应该尝试将所有内容都保存在自己的php文件中,然后插入一个动作以html形式调用php文件?我一到家就试试这个。你可以用任何你想用的东西作为动作,例如,发到JPG,但不会有什么效果。没有理由不能在.html页面中使用表单并将其发布到php脚本。
<?php
if( isset($_POST) ){

    //form validation vars
    $formok = true;
    $errors = array();

    //sumbission data
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date = date('d/m/Y');
    $time = date('H:i:s');

    //form data
    $name = $_POST['name']; 
    $email = $_POST['email'];
    $message = $_POST['message'];

    //validate form data

    //validate name is not empty
    if(empty($name)){
        $formok = false;
        $errors[] = "You have not entered a name";
    }

    //validate email address is not empty
    if(empty($email)){
        $formok = false;
        $errors[] = "You have not entered an email address";
    //validate email address is valid
    }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
        $formok = false;
        $errors[] = "You have not entered a valid email address";
    }

    //validate message is not empty
    if(empty($message)){
        $formok = false;
        $errors[] = "You have not entered a message";
    }
    //validate message is greater than 20 charcters
    elseif(strlen($message) < 20){
        $formok = false;
        $errors[] = "Your message must be greater than 20 characters";
    }

    //send email if all is ok
    if($formok){
        $headers = "From: name@email.com" . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        $emailbody = "<p>You have received a new message from the form on your website.</p>
                      <p><strong>Name: </strong> {$name} </p>
                      <p><strong>Email Address: </strong> {$email} </p>
                      <p><strong>Message: </strong> {$message} </p>
                      <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";

        mail("name@email.com","New Enquiry",$emailbody,$headers);

    }

    //what we need to return back to our form
    $returndata = array(
        'posted_form_data' => array(
            'name' => $name,
            'email' => $email,
            'telephone' => $telephone,
            'enquiry' => $enquiry,
            'message' => $message
        ),
        'form_ok' => $formok,
        'errors' => $errors
    );


    //if this is not an ajax request
    if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){
        //set session variables
        session_start();
        $_SESSION['cf_returndata'] = $returndata;

        //redirect back to form
        header('location: ' . $_SERVER['HTTP_REFERER']);
    }
}
?>