我可以使用jQuery向php文档添加代码吗? [英] Can I use jQuery to add code to a php document?

查看:111
本文介绍了我可以使用jQuery向php文档添加代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个网站上工作,该网站可以添加多个人,您可以从一个人开始进行订阅,并且可以根据需要添加更多人.

I'm working on a site where you have a form that can add multiple persons, you start with one person to subscribe and can add more if you like.

我编写了一个供1个人使用的PHP文档,但是如果我使用多人,我希望更改它.

I have written a PHP document that's made for 1 person, but I like it to change if I use multiple persons.

是否可以通过使用一些jQuery代码来更改我的mail.php?

Is it possible to change my mail.php with the use of some jQuery code?

脚本

var x = 0;

$('#addPlayer').on('click', function() {
            x++;
        });

if(x > 0) {
    for(i = x; i>=0; i--) {
        // add extra persoon to mail.php
    }
}
else {
    mail.php
}

if (i == 0) {
    use new mail.php
}

每次添加新玩家(单击按钮)时,他们都是计数.

For every time a new player has been added (click on button) their is a count.

mail.php

<?php
$to = "example@mail.com";
$from = $_POST['email'];
$name = $_POST['name'];
$voornaam = $_POST['first_name'];
$geboortedatum = $_POST['date'];
$telefoon = $_POST['phone_number'];
$type = $_POST['r0'];
$adres = $_POST['address'];
$postcode = $_POST['postcode'];
$huisnr = $_POST['number'];
$gemeente = $_POST['municipality'];
$prijs = $_POST['price'];

//getting the new inputs for a new player
//extra persoon
$naam1 = $_POST['spname1'];
$voornaam1 =$_POST['Firstname1'];
$mail1 = $_POST['spemail1'];
$geboortedatum1 = $_POST['datepicker1'];
$telefoon1 = $_POST['sptele1'];
$type1 = $_POST['r1'];



//getting the new inputs for a new player
$naam2 = $_POST['spname2'];
$voornaam2 =$_POST['Firstname2'];
$mail2 = $_POST['spemail2'];
$geboortedatum2 = $_POST['datepicker2'];
$telefoon2 = $_POST['sptele2'];
$type2 = $_POST['r2'];

$myArray = array( "nul", "volwassene", "student", "kind met 8 lessen", "kind zonder 8 lessen");
//array that selects the right value for type

$bericht = "Beste " . $voornaam . " " . $name . ",\n" . "We hebben uw inschrijving goed ontvangen. \nHier hebt u nog eens de inschrijving. Als er iets niet correct zou zijn laat het ons weten (info@kltc.be). \n\r\n\r" . "NAAM: " . $voornaam ." ". $name . "\n E-MAIL: " . $from . "\n GEBOORTEDATUM: " . $geboortedatum . "\n TELEFOON: " . $telefoon . "\n TYPE: " . $myArray[$type] . "\n ADRES: " . $adres . "\n POSTCODE: " . $postcode . "\n HUISNR: " . $huisnr . "\n GEMEENTE: " . $gemeente . "\n PRIJS: " . $prijs . "\n\r\n\r Gelieve dit bedrag te storten op het rekeningnummer: IBAN: BE59 0017 9225 2226 van KLTC HERENT vzw of BIC: GEBABEBB \n\r met de vermelding : 'lidmaatschap 2019 '-' X aantal personen / gezin / lessen, ... enz.' \n Uw inschrijving is pas definitief als zowel het lidgeld betaald is en we het inschrijvingsformulier ontvangen hebben. \n !Deelname aan tennislessen kan alleen, nadat je het lesgeld betaald hebt. \n\r\n\r Wij hier bij KLTC HERENT heten u alvast welkom! \n\r\n\r !Dit is mogelijk gemaakt door Tobias Van Rickstal!";

$subject = "Inschrijving";
$subject2 = "Inschrijving bij KLTC";

$headers = "From: $from";
$headers2 = "From: $to";

mail($to,$subject,$bericht,$headers) or die("Error!");

            echo "Bedankt," . $voornaam . $myArray[$type];
?> 

我是否应该使用一条额外的消息( bericht )?还是我应该如何最好地做到这一点?

Should I use an extra message(bericht)? or how should I do this the best way possible?

我在邮寄方面也遇到了一些问题,我想向填写表格的人发​​送一封确认信.所以一个给接收者,一个给发送者,但是我遇到了一些问题.或者,我的收件箱里只有一个,或者我收到的是空邮件(邮件中没有发布我输入的任何信息.

I also had some issues with the mailing, I would like to send a confirmation to the one who has filled the form. so one to the receiver and one to the sender, but I had some problems with it. Or I get only one in my inbox or I get an empty mail (no information of my inputs were published in the mail.

推荐答案

PHP是一种服务器端语言,可在Web服务器上运行.

PHP is a server-side language and runs on the webserver.

jQuery/javascript是一种客户端语言,可在每个用户的计算机上的浏览器中运行.

jQuery/javascript is a client-side language and runs on each user's computer, in the browser.

再想一想这两个计算机在哪里 -它们可能相距数英里.

Think for a second where these two computers are - they could be miles apart.

为了使jQuery与PHP文件通信,您必须使用FORM(将用户输入的数据发送到Web服务器PHP文件)或使用AJAX.

In order for jQuery to communicate with PHP files, you must either use a FORM (which sends the user-typed data to the webserver PHP file), or use AJAX.

FORM方法非常老,只能发送数据. AJAX方法更新得多,可以发送和接收. AJAX是我们与服务器进行对话并接收响应的方式(例如在数据库中查找用户名/密码之类的内容)并更新页面而不刷新整个页面. (表单始终会离开当前页面并转到处理(PHP)文件.)

The FORM method is very old and can only SEND data. The AJAX method is much newer and can both SEND and RECEIVE. AJAX is how we talk to the server and receive a response back (e.g. look something up in a database, like username/password) and update the page without refreshing the entire page. (Forms always leave the current page and go to the processing (PHP) file.)

Mail.php 将通过从HTML表单接收数据,将数据填充到变量中并发送电子邮件来工作.用户必须以HTML表单填写所有数据.当用户按下SEND(或任何您称呼submit按钮)时,用户提供的数据将发送到后端PHP文件,插入正确的PHP变量,然后PHP才会生成电子邮件并发送.

Mail.php will work by receiving data from an HTML form, filling the data into the variables, and sending the email. All the data must be filled-in by the user in the HTML form. When user presses SEND (or whatever you call your submit button) the user-supplied data will be sent to the back-end PHP file, plugged into the right PHP variables, and only then will PHP generate the email and send it.

因此...将新用户添加到您的mail.php文件中是手动完成的操作(由用户再次填写表单),然后单击发送".每次发送后,表格都会被删除.

So... adding a new user to your mail.php file is something that is done manually (by the user filling out the form again) and clicking Send. The form is erased after each Send.

有关表单和AJAX的简单介绍,请参见下文:

See below for a simple introduction to forms and AJAX:

HTML表单

AJAX基础

jQuery AJAX简介-w3schools

这篇关于我可以使用jQuery向php文档添加代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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