duanfoumi5620 2014-06-06 04:12
浏览 62
已采纳

使用PHP的HTML表单行为

I ran into an interesting wall today working on a simple form with PHP and HTML and can't think of a quick fix.

I'm using the PHP script I've written when the user presses submit on my HTML page. In order to re-display the page after running the script I simply write

include "html_forms.html" 

at the bottom of the PHP script. Firstly, this seems like a bad design for presenting the page as it needs to be constantly fully re-displayed but I couldn't figure out how to circumvent this problem.

The problem I'm more concerned with here though is that I'm trying to keep the form data from before the user first pressed submit by using PHP. To do this I modify the value of each input like this (within the HTML):

value = "<?php echo $website; ?>

However, when the webpage is first loaded from the HTML (I'm guessing it can't find the PHP to reference since the Submit button hasn't been clicked yet so) in my entry box on the page the first time it's loaded it prints <?php echo $website; ?>. If I load the PHP first it doesn't have that problem but this schism makes me question the overall design that I'm going for and although it might fix the problem in this case it seems like it only works because the simplicity of the webpage.

My main question is how to fix this? I've thought of looking into just emptying the html entries on the first go and other techniques but I'm not sure if this would be the best approach since making special cases especially for the first time the page is clicked seems like bad form.

Thanks in advance for the help guys and this is the first question I've asked on stack-overflow so let me know if there's anyway I could improve my question-asking and don't be too harsh on me!

  • 写回答

2条回答 默认 最新

  • doulu4203 2014-06-06 04:31
    关注

    Basically the issue is that your web server does not parse .html files by PHP interpreter. You have two options from here:

    1. If you use Apache you may configure .htaccess to have following line:

      AddHandler php5-script .html

    2. You may rename your .html file into .php file

    However both options are bad design: you should allow user to interact with your PHP script only and use underlying html as template if needed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 找学习通代刷,来不及啦,来不及啦!
  • ¥15 arcgis栅格数据重分类后有八类,进行栅格转面后转出的面要素只有一个分类后获得的grid_code,是什么原因?
  • ¥15 51单片机程序设计题
  • ¥15 ARCH模型 Python
  • ¥50 python爬虫怎么不用selenmium的条件下实现按钮点击
  • ¥15 matlab中spectrogram函数的使用
  • ¥15 matlab中spectrogram函数的使用
  • ¥15 有可以做抢票软件的联系我,不犯法
  • ¥15 (标签-matlab|关键词-m3)
  • ¥500 一款发光产品,需要做出幻彩LED效果方案开发