LagAbuse.com
Unofficial Section => Programming => Topic started by: Renovatio on October 17, 2015, 19:27
-
Does anyone knows how to code this?
So, I have a <div> in my html page that grabs some content with javascript variables. I need to make a PHP script that send that content in a email.
I found out on internet that I need to make a jQuery script that sends my content to the PHP script wich emails it.
This is a part of my content:
<div id="content">
<meta charset="UTF-8">
<table border=”1″ style=”width:1000px”>
<tr >
<td class='myclass'><b>Nume:</b><span id='nm'></span>, <span id='pm'> </span><b> Vârsta:</b><span id='demo'></span> <b>Sex:</b><span id='sx'></span> <b>Data:</b> <span id='time'></span></td>
</tr>
</table>
<table border=”1″ style=”width:1000px”>
<tr>
<td><b>Somatizare</b></td>
<td><b>Obsesiv/<br>Compulsiv</b></td>
...
<content> <content> <content>
...
<span id='showipI'></span> <br><br>
<span id='showpsiI'></span> <br><br>
<span id='showdom'></span><br><br>
</p>
</div>
This is my PHP script:
<?php
$to = "my_email_acc";
$subject = "HTML Data";
$message = $_POST["content"];
$headers = "From: The Server <server@doe.com>" . "\r\n" .
"Content-type: text/html" . "\r\n";
mail($to, $subject, $message, $headers);
?>
jQuery script ??
-
var some_status_element = $('#status'),
content = $('#content');
function send_a_deer() {
$.post({
url:'path/to/yourmegaphpscript.php',
type:'post',
data: {content: content.html()},
beforeSend: function() {
some_status_element.html('loading...');
},
success: function() {
some_status_element.html('done!');
},
error: function() {
some_status_element.html('deered. error happenederedeered');
}
})
}
Something like this
mby i got some syntax errors, coz woke up and typed code right in this lil message input box
but logics is right
//go create some element with id 'status', empy one
-
But ur task is so bad
u should just send some important unique variables from js, not whole email body (try to never deer with user internet traffic, pls :s, send as less data as u can. And do response with less data)
And generate that 'html structure' in PHP again before emailing;
also purify these from some random stuff
at least with htmlspecialchars() function
Veri bed, renovatio, veri bed.
dir english
The mini deer goes here.
(http://hddesktopwallpapers.in/wp-content/uploads/2015/08/deer-horns-sunset-picures.jpg)
-
There are to many variables, about 20 and I want them displayed in a complex table. I'm not quite a coder master. I needed to make some questionnaires and I made them using only documentation found on net.
I've pasted your code in:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
here
</script>
I've replaced path to PHP script but I don't know what element you need me to create.
Do I send the content to PHP script by using <form name="name" method="post" action="myscript.php"> and submit button or I need to call your function too?
-
I did it!
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#sendEmail').click(function(){
$.ajax({
type: 'POST',
url: 'http:mydomain/etc/send_form_email.php',
data: { content: $('#email-data').html()}
});
});
});
</script>
<div id="email-data">
<div id="content">
my content
</div>
</div>
<a href="#" id="sendEmail" >Send Email</a>
Ty dude! :)
-
I need help again.
My div content is hidden and when I send it via email with my php script is still hidden.
How do I code the php script to dispay my div in email?
<div id="content" style="visibility:hidden">
<?php
$to = "admin@mail.com";
$subject = "Rezultate chestionare";
$message = $_POST["content"];
$headers.= "Content-Type: text/html;charset=utf-8\r\n";
mail($to, $subject, $message, $headers);
?>
I think this piece of code should be added to php script to dispplay it but I don;t know where to put it.
<script type=\"text/javascript\">document.getElementById('".$content."').style.display = 'block';</script>
-
You deer can replace this stuff
data: {content: content.html()},
with this
data: {content: content.clone().css('display', 'block').html()},
But it sucks
better do it on php side (but it sucks too):
$message = str_replace('id="content" style="visibility:hidden"', 'id="content"', $_POST['content']);
Also i'd like to show u some example:
Some lil kid called hacker (lets call him Ayd.Mev) will use this stuff in google chrome console (actually he should send raw request from something else, but no, he's lil kid called hacker):
$.ajax({
type: 'POST',
url: 'http:mydomain/etc/send_form_email.php',
data: { content: 'Hahaha disregard that, i suck cocks! (c) [some hard porn pic here]'}
});
And ull get excactly what Ayd.Mev sent to u instead of your lil #content
So if u're coding some serious stuff, i might waste some time to explain how do things work, ask mi, dir helps
Also in PHP in places where u're using strings, like $_POST['content'], dont use double quotes, use these ' stuffs. It will decrease execution time
U should use double quotes in php only when you are deering some variable in some string, e.g. : $_POST["deer_prefix_$variable"]. Php engine will replace $variable with value of $variable here. If ull use just ' this stuff, php engine will ignore anything and interprete it as string
Also u should use your little double quotes when u have to insert some special symbol (like \n, \r, \t and so on), use "\n" for these
Deers!
-
btw u got 2 errors in ur php code
remind me later to explain and teach you some little things
-
I've made this:
<?php
$to = 'my_mail';
$subject = 'Rezultate chestionare';
$message = str_replace('id="content" style="visibility:hidden"', 'id="content"', $_POST['content']);
$headers.= 'Content-Type: text/html;charset=utf-8"\r\n"';
mail($to, $subject, $message, $headers);
?>
It works now.
About errors: do you reffer at "from"? It says "no from address" when I open the email.
I have input type=email in my form. I got it's value in a variable and then displayed it innerhtml, with <span>, in my <div> content. So I can see it in the emai I recieve but not as "from" in header.
Another problem. I have 2 buttons:1 for sending the content to php script, and another one that computes my form. The form needs computing before it gets send to email, because the <div> content is the form's results.
Computing form:
<input id="btnClickMe"
type="button"
value="Am terminat"
onclick=computeForm(this.form) />
Sending to php script:
<a href="#" id="sendEmail" >Send Email</a>
Can I merge this 2 in one button?
-
http://php.net/manual/ro/function.mail.php
Example #2 for from
You can export this email in javascript from that lil innerhtml and send it like this:
data: { content: $('#email-data').html(), email: some_email_variable_here}
then get it with $_POST['email'] and validate it with http://php.net/manual/ro/filter.examples.validation.php example from here
About your buttons
Never motherdeering use 'onclick' in html structure
Since u have jQuery, use some $('selector').on('click', function() { /* DEER STUFF */ });
I should know how does calculateForm work
If its sync function, u can just call it like this:
$('#sendEmail').click(function(){
computeForm();
$.ajax({
type: 'POST',
url: 'http:mydomain/etc/send_form_email.php',
data: { content: $('#email-data').html()}
});
});
And delete this useless this.form from argument
Find that form with selector or document.getElement... right in function computeForm
Actually u should create some variable in script scope, like var form = document.getElement...;
then use this 'form' variable in function
About errors:
no, you have this string in code
$headers.= "Content-Type: text/html;charset=utf-8\r\n";
thats veri bed, Renovatio, veri bed.
Dont use '.=', '*=', '+=' and other stuff if you didnt set variable before
Cause it will generate error and waste some system resources
If you did never set this $headers, use just '=' then;
Also use single quotes as i said before, instead of double ones in $to and $subject strings
Im sick a bit and if i failed my english hard here, inform me, so ill rewrite these explanations better
p.sp btw in 1st ur post you have nice From: header without this error, cause u didnt use lil .= operator
-
I solved that error, now I got "from". I used single quotes. With email it didn't worked but is not to important, anyway. That content is sent to my email, not to users, I get their email address in div content, in case I want to send them their form results.
Important is not to make them click 2 buttons because if 1 isn't clicked the other one is clicked for nothing. This is my last problem, the rest looks fine.
I've called the form function like this: $('#sendEmail').click(function(){
computeForm(); but it didn't worked, actually I didn't recieved mail after doing this.
I've deleted this.form and the form didn;t compute itself after that.
My form function is kinda messed up. Is very very big and unnecesary complicated but it works. It looks something like this:
<script type="text/javascript">
function test_it(entry) {
if (entry.value!=null && entry.value.length!=0) {
entry.value=""+ eval(entry.value);
}
computeForm(entry.form);
}
function computeForm(form) {
var sos=0
var som=0
declaring more variable etc etc
calculating my form factors
for (var count=0; count<5; count++)
{
if (form.i1[count].checked){
var som=som+parseInt(form.i1[count].value);
}
}
for (var count=0; count<5; count++)
{
if (form.i4[count].checked){
var som=som+parseInt(form.i4[count].value);
}
}
for (var count=0; count<5; count++)
{
if (form.i12[count].checked){
var som=som+parseInt(form.i12[count].value);
}
}
etc etc
calculating percentage of some answears (my form items have 5 options each)
for (var count=0; count<5; count++)
{
if (form.i4[count].checked && parseInt(form.i4[count].value)==4){
var strp=strp+1;
} else if (form.i4[count].checked && parseInt(form.i4[count].value)==3) {
var strr=strr+1;
}
}
for (var count=0; count<5; count++)
{
if (form.i5[count].checked && parseInt(form.i5[count].value)==4){
var strp=strp+1;
} else if (form.i5[count].checked && parseInt(form.i5[count].value)==3) {
var strr=strr+1;
}
}
for (var count=0; count<5; count++)
{
if (form.i6[count].checked && parseInt(form.i6[count].value)==4){
var strp=strp+1;
} else if (form.i6[count].checked && parseInt(form.i6[count].value)==3) {
var strr=strr+1;
}
etc etc
setting standard values for some factors in condition to user's sex and age.
if (document.getElementById("vn").value < 20 && s==0) {
somD=0.75
somDD=1.58
} else if (document.getElementById("vn").value >= 20 && s==0) {
somD=0.75
somDD=1.49
} else if (document.getElementById("vn").value < 20 && s==1) {
somD=0.33
somDD=0.92
} else if (document.getElementById("vn").value >= 20 && s==1) {
somD=0.42
somDD=1.08
}
etc etc etc
calculating global factors
GSI=(som + oc + sip + dep + anx + om + af + ip + psi) /90
PSDI=(som + oc + sip + dep + anx + om + af + ip + psi)/stru
etc etc
setting text as interpretation for factors values
if (PSDI>=psdiDD && PSDI < 3) {
psdiI="Intesitatea simptomelor depăsește limita normală și respondentul indică o suferință psihică reală."
} else if (PSDI >= psdiD && PSDI < psdiDD ) {
psdiI="Intensitatea simptomelor este semnificativă și indică probabilitatea unei suferințe psihice."
} else if (PSDI < psdiD) {
psdiI="Intensitatea simptomelor se află în limite normale."
} else if (PSDI>=3) {
psdiI="Intensitatea simptomelor a depășit cu mult limita normală și, cel mai probabil, respondentul prezintă o suferință psihică agravată."
}
etc etc etc
getting those variables in innerhtml
document.getElementById('showsomM').innerHTML = somM;
document.getElementById('showocM').innerHTML = ocM;
document.getElementById('showsipM').innerHTML = sipM;
document.getElementById('showdepM').innerHTML = depM;
etc etc etc
}
</SCRIPT>
After that comes the form:
<form METHOD=POST>
with input type text, number, email and the rest of it (91 items) radio.
<center><div><input id="btnClickMe"
type="button"
value="Am terminat"
onclick=computeForm(this.form) />
</div></center>
</form>
</body>
And after that comes the hidden div with form variables displayed via <span>
You helped me a lot so is ok if you can't help me with this problem too. Ty deer! ;D
-
but u didnt declare that form variable in script scope -_-
where is
var form = document.getElement.... ?
also u didnt delete (form) from function arguments :s
-
im ingame and cant explain stuff:D
-
I did it. Is working now. ;D
I didn't knew how to declare form's variable because it didn't had an ID.
I deleted this part:
function test_it(entry) {
if (entry.value!=null && entry.value.length!=0) {
entry.value=""+ eval(entry.value);
}
computeForm(entry.form);
}
I don't know if was important or not.
I deleted form from function arguments.
I've placed an ID for my form:
<form id="form" METHOD=POST>
and I modified my jQuery script like this:
$(document).ready(function(){
var sform = document.getElementById("form").innerHTML;
$('#sendEmail').click(function(){
computeForm(sform);
$.ajax({
type: 'POST',
url: 'http://chestionare.byethost12.com/wp/send_form_email.php',
data: { content: $('#email-data').html()}
});
});
});
</script>
Tnx, dude. I couldn't do it without you.
-
Thats cute
And most cute part here is u did it urself, i only sent u right way and didnt explain whole stuff; So u learn some deer things
-
and if u deleted form from agruments, dont pass this argument there:
computeForm(sform);
use just
computeForm();
-
WTF is all this?? And i thought "coding" is fun, this is chinese lol
-
WTF is all this?? And i thought "coding" is fun, this is chinese lol
Coding in Pascal is pretty fun, is easy. I was very good at it in highschool, but is outdated and useless. JQuery and PHP are truly chinese, I don't know to code in them, I am using google documentation and my own logic.
Welcome back, dude! ;D
-
I am stupid and i find this offensive.
-
WTF is all this?? And i thought "coding" is fun, this is chinese lol
Coding in Pascal is pretty fun, is easy. I was very good at it in highschool, but is outdated and useless. JQuery and PHP are truly chinese, I don't know to code in them, I am using google documentation and my own logic.
Welcome back, dude! ;D
At first I was so curious about codin, but at the end - NOP :P
Good to see you around Reno :*
-
I am deer and i find this defensive.