我对PHP比较陌生,所以如果这看起来很明显,请原谅我。你将如何整合这样的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>
进入这里:
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>";
}
提前感谢您的帮助。
答案 0 :(得分:1)
因此,一个选项是echo
逐行排列,就像PHP代码示例一样,或者在一个大块中。您还可以通过启动和停止PHP解释器在同一文件中组合PHP和HTML。这是一个例子:
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
}
在专业的制作应用程序中,正确的方式&#34;要做的就是将你的HTML与PHP分开,方法是将应用程序的逻辑放在一个单独的PHP文件中,然后将你的HTML放在&#34;模板中。你从PHP加载和显示。 Here是关于在应用程序中开始使用模板引擎和模型视图控制器模式的一些信息。但是,对于您尝试做的事情,上面启动和停止解释器的示例应该适合您。