简体   繁体   English

PHP块中的HTML联系人表格

[英]HTML contact form in PHP block

I'm relatively new to PHP so forgive me if this seems obvious. 我对PHP相对较新,所以如果这很明显,请原谅我。 How would you integrate a block of HTML code like this: 您将如何集成这样的HTML代码块:

 <form action="form.php" method="post" enctype="multipart/form-data">

        <label></label>
        <input name="name" required="required" placeholder="Your Name">


        <label></label>
        <input name="email" type="email" required="required" placeholder="Your Email">

            <label></label>
        <input name="address" type="name" required="required" placeholder="Your Address">


        <label></label>
        <textarea name="message" required > Dear Mr. X, Please support us...  </textarea>


        <input id="cancel" name="cancel" value="Cancel" />

        <input id="submit" name="submit" type="submit" value="Submit">

    </form>

into here: 进入这里:

if(empty($mpemail)){

echo "<h2>Send your MP our pre-written letter</h2>
<p>Unfortunately, your MP's email address is not listed in our database.</p>";
}

else {

echo "<h2>Send your MP our pre-written letter</h2>";
echo "<p>Please fill out the information required below:</p>";   
  **Insert Contact Form Here**
echo "<h2>Share this with your followers!</h2>";
echo '<a href="https://twitter.com/share" class="twitter-share-button"          data-text="I just used EG4DEMUK\'s handy tool to write to my local MP about Egypt!" data-size="large" data-hashtags="writetoyourmp">Tweet </a>';
echo "<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>";
}

Thanks in advance for your help. 在此先感谢您的帮助。

So, one option is to echo it out line by line, as your PHP code sample is doing, or in one big block. 因此,一种选择是按照您的PHP代码示例所做的,或者在一个很大的块中逐行echo它。 You can also combine PHP and HTML in the same file by starting and stopping the PHP interpreter. 您还可以通过启动和停止PHP解释器,将PHP和HTML合并在同一文件中。 Here's an example of that: 这是一个例子:

if (empty($mpemail))
{
    echo "<h2>Send your MP our pre-written letter</h2>
    <p>Unfortunately, your MP's email address is not listed in our database.</p>";
}
else
{
?>

<h2>Send your MP our pre-written letter</h2>
<p>Please fill out the information required below:</p>

<form action="form.php" method="post" enctype="multipart/form-data">
    <label></label>
    <input name="name" required="required" placeholder="Your Name">

    <label></label>
    <input name="email" type="email" required="required" placeholder="Your Email">

    <label></label>
    <input name="address" type="name" required="required" placeholder="Your Address">


    <label></label>
    <textarea name="message" required > Dear Mr. X, Please support us...  </textarea>

    <input id="cancel" name="cancel" value="Cancel" />
    <input id="submit" name="submit" type="submit" value="Submit">
</form>


<h2>Share this with your followers!</h2>
<a href="https://twitter.com/share" class="twitter-share-button" data-text="I just used EG4DEMUK\'s handy tool to write to my local MP about Egypt!" data-size="large" data-hashtags="writetoyourmp">Tweet </a>

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

<?php
}

In a professional production application, the "right way" to do it is to separate your HTML from your PHP by putting the logic of your application in a separate PHP file, and then putting your HTML in a "template" which you load and display from PHP. 在专业的生产应用程序中,“正确的方法”是通过将应用程序的逻辑放在单独的PHP文件中,然后将HTML放入加载和显示的“模板”中,从而将HTML与PHP分开。从PHP。 Here is a bit of info about getting started with template engines and Model View Controller patterns in an application. 以下是有关在应用程序中开始使用模板引擎和Model View Controller模式的一些信息。 But, for what you're trying to do, the example above of starting and stopping the interpreter should work for you. 但是,对于您要尝试执行的操作,上面启动和停止解释器的示例将为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM