有关使用PHP处理HTML表单数据的建议-可以使用Python吗? [英] Recommendations for handling HTML form data using PHP - and may Python?

查看:48
本文介绍了有关使用PHP处理HTML表单数据的建议-可以使用Python吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP制作一个非常简单的HTML表单.我希望表格执行:

I am making a very simple HTML form using PHP. I would like the form to execute:

  1. 发送给用户的电子邮件(完成)
  2. 导出到SQL数据库(我已设置数据库)
  3. 在页面上显示输入,并可以选择将结果下载为.csv和.pdf

另一个问题,什么是最佳实践:

Another question, what is the best practice:

  1. 已将.php文件上传到FTP服务器(或)
  2. 在HTML文件中写入php脚本吗?

最后,改为用Python编写php脚本会更容易吗?

Finally, would it be easier to write the php script in Python instead?

以下是php代码:

    <?php
$date = $_POST['date'];
$client = $_POST['client'];
$session = $_POST['session'];
$session_type = $_POST['session_type'];
$progress = $_POST['progress'];
$previous_session = $_POST['previous_session'];
$verbal = $_POST['verbal'];
$body_language = $_POST['body_language'];
$mood = $_POST['mood'];
$objective = $_POST['objective'];
$assessment = $_POST['assessment'];
$goals = $_POST['goals'];
$quotes = $_POST['quotes'];
$summary = $_POST['summary'];

$formcontent="Client name: $client \n
Date: $date \n
Meeting: $session \n
Session type: $session_type \n
Progress: $progress \n
Previous session: $previous_session \n
Verbal: $verbal \n
Body language: $body_language \n
Mood: $mood \n
Objective: $objective \n
Assessment: $assessment \n
Goals: $goals \n
Client quotes: $quotes \n
Summary of session: $summary";
$recipient = "maryknauth@mac.com";
$subject = "Case notes for $client on $date";
$mailheader = "From: mySportPsych Admin \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You, the case notes submitted have been emailed to $recipient and are also listed below:\n
Client name: $client\n
Date: $date\n
Meeting: $meeting\n
Session type: $session_type\n
Progress: $progress\n
Previous session: $previous_session\n
Verbal: $verbal\n
Body language: $body_language\n
Mood: $mood\n
Objective: $objective\n
Assessment: $assessment\n
Goals: $goals\n
Client quotes: $quotes\n
Summary of session: $summary";?>

这是HTML表单:

        <form action="case_notes.php" method="post">
     <h4 class="text-form-section">Overview</h4>
        <hr class="style-hr">
     <!-- Date -->  
    <label for="date" class="label">Date</label>
        <br>
    <input name="date" type="date" class="input-text" id="date">
        <br>
<!-- Client --> 
    <label for="client" class="label">Client</label>
        <br>
    <input name="client" type="text" class="input-text" id="client">
        <br>
<!-- Session -->
<!-- Is this supposed to be a number? -->
    <label for="session" class="label">Session</label>
        <br>
    <input name="session" type="text" class="input-text" id="session">
        <br>
<!-- Type of Session -->
    <label for="session_type" class="label">Session Type</label>
        <br>
        <select name="session_type" id="session_type">
            <option value="null"></option>
            <option value="free">Free Consultation</option>
            <option value="initial">Initial Consultation</option>
            <option value="regular">Regular Consultation</option>
            <option value="termination">Termination</option>
            <option value="other">Other</option>
        </select>   
        <br>

<!-- Progress -->
    <label for="progress" class="label">Progress</label>
        <br>
        <select name="progress" id="progress">
            <option value="null"></option>
            <option value="very_good">Very Good</option>
            <option value="good">Good</option>
            <option value="none">No Progress</option>
            <option value="regression">Regression</option>
        </select>   

      <br>
        <br>
<!-- Previous session review -->    
    <label for="previous_session" class="label">Previous session review</label>
        <br>
    <input name="previous_session" type="textarea" class="input-text" id="previous_session" rows="5" cols="30">
        <br>
 <!-- Subject Review -->
    <div class="subject review">    
    <h4 class="text-form-section">Subject</h4>
        <hr class="style-hr">
    <label for="verbal" class="label">Verbal</label>
        <br>
    <input name="verbal" type="textarea" class="input-text" id="verbal" rows="5" cols="30">
        <br>
    <label for="body_language" class="label">Body Language</label>
        <br>
    <input name="body_language" type="textarea" class="input-text" id="body_language" rows="5" cols="30">
        <br>
    <label for="mood" class="label">Mood</label>
        <br>
    <input name="mood" type="textarea" class="input-text" id="mood" rows="5" cols="30">
    </div>
    <h4 class="text-form-section">Session Review</h4>
        <hr class="style-hr">
    <label for="objective" class="label">Objective</label>
        <br>
    <input name="objective" type="textarea" class="input-text" id="objective" rows="5" cols="30">   
        <br>

    <label for="assessment" class="label">Assessment</label>
        <br>
    <input name="assessment" type="textarea" class="input-text" id="assessment" rows="5" cols="30">
        <br>

    <label for="goals" class="label">Goals</label>
        <br>
    <input name="goals" type="textarea" class="input-text" id="goals" rows="5" cols="30">
        <br>

    <label for="quotes" class="label">Client Quotes</label>
        <br>
    <input name="quotes" type="textarea" class="input-text" id="quotes" rows="5" cols="30">
        <br>

    <label for="summary" class="label">Summary</label>
        <br>
    <input name="summary" type="textarea" class="input-text" id="summary" rows="5" cols="30">
        <br>
        <br>

    <input type="submit" class="button">

</form> 

推荐答案

  1. 我看不到任何< input>表单中的电子邮件字段.要向用户发送电子邮件,您应该通过表格从用户那里收到电子邮件地址.正确的?另外,您已在 mail()函数中将您的电子邮件地址用作收件人.在表单中添加电子邮件"字段后,别忘了在分配给 mail()之前验证电子邮件.

  1. I am not able to see any <input> field for Email in your form. To email the user you should receive the email address from the user via a form. Right? Also, you have used your email address as recipient in the mail() function. Once you add the Email field in the form do not forget to validate the email before assigning into mail().

我假设您需要将表单数据插入数据库中.为此,您应该使用SQL查询在PHP数据库表中创建一个使用PHP和INSERT的数据库连接.

I assume you need to insert the form data into the Database. For that, you should create a DB connection with PHP and INSERT into the Database table with SQL Queries.

在页面上显示数据很简单,我可以将其与您的其他问题相关在HTML文件中编写PHP脚本?.您不能在HTML文件中运行PHP脚本,反之亦然.您可以用PHP脚本编写HTML!因此,您可以将上述两个文件合并为一个PHP文件,也可以将表单拆分为HTML文件,然后将请求拆分为PHP文件,然后将表单数据输出到表中(在插入数据库,邮件等之后).

Showing the Data on the page is simple and I can relate this to your other question Write the PHP script in the HTML file?. You can't run a PHP Script in an HTML file but the other way around. You can write HTML in a PHP script! So you can combine both above files into a single PHP File or you can split the form in an HTML file and process the request in a PHP file and output the Form Data in a Table (After DB Insertion, Mail etc).

相反,用Python编写PHP脚本会更容易

would it be easier to write the PHP script in Python instead

不.您不能在python文件中编写PHP,也不能表示是否应使用Python编写.这完全取决于您.我会说PHP入门比较容易,但很难掌握.正确地做基础知识,清楚,清楚地理解概念.另外,请清楚了解相关技术(HTTP,邮件)及其工作原理.

No. you can't write PHP in a python file or if you mean whether you should write in Python. It's completely upto you. I would say PHP is easier to begin with but harder to master. So do the basics right, understand the concepts clear and well. Also, understand the related technology (HTTP, Mail) and their working clearly.

最后,请花一些时间慢慢而稳定地建立知识.

Lastly, take your time and build knowledge slow and steady.

以下链接将帮助您了解:

Following links will help you learn that:

PHP MySQL简介

PHP MySQL插入

PHP表单处理

这篇关于有关使用PHP处理HTML表单数据的建议-可以使用Python吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆