Webprogramozás arr PHP info Formtoemail.php kiegészítés
(#1) ben89 2013.01.15. 13:00

ben89
ben89
Kezdő

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-language" content="en">
<meta name="Author" content="jeanray charlier"> 
<meta name="copyright" content="jeanray charlier">
<style type="text/css">
body
{
    FONT-FAMILY: verdana, arial, times;
    font-size: 12px;
    color: #000000;
    margin: 0 0 0 0;
} 
.title
{
    color: #0000FF;
    font-size: 14px;
    font-weight: bold;
}
</style>
<?php
    // YOUR EMAIL ADDRESS
    define ("MYEMAIL",""); // YOU MUST ENTER YOUR EMAIL HERE
 
function show_form()
{
    $txt  = "<p class=\"title\" align=\"center\"><b>Form to email Script</b></p>";
    $txt .= "<form name=\"f2email\" action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
    $txt .= "<table align=\"center\">";
    $txt .= "<tr><td>Your name:</td><td><input type=\"text\" name=\"name\" /></td></tr>";
    $txt .= "<tr><td>Your email:</td><td><input type=\"text\" name=\"email\" /></td></tr>";
    $txt .= "<tr><td>Subject:</td><td><input type=\"text\" name=\"subject\" size=\"40\" /></td></tr>";
    $txt .= "<tr><td colspan=\"2\">Your Comment:</td></tr>";
    $txt .= "<tr><td colspan=\"2\"><textarea name=\"comment\" rows=\"5\" cols=\"60\"></textarea></td></tr>";
    $txt .= "<tr><td colspan=\"2\" align=\"right\">";
    $txt .= "<input type=\"button\" name=\"send\" value=\"Send\" 
                onclick=\"js_validate(document.forms['f2email']); return false;\" /></td></tr>";
    
    // REMOVE THE FOLLOWING LINES WHEN YOU HAVE DEFINED "MYEMAIL"
    if (MYEMAIL == "")
    {
        $txt .= "<tr><td>Email To:</td><td><input type=\"text\" name=\"toemail\" /></td></tr>";
        $txt .= "<tr><td colspan=\"2\" >(You must edit the code and define \"MYEMAIL\")</td></tr>";
    }
    // ===================================================================
    $txt .= "</table>";
    $txt .= "<input type=\"hidden\" name=\"submitted\" value=\"submitted\" />";
    $txt .= "</form>";
    return($txt);
}
function treat_submission()
{
    $name = $_POST['name']; // VISITOR'S NAME
    $email = $_POST['email']; // VISITOR'S EMAIL
    $subject = $_POST['subject'];
    $comment = $_POST['comment'];
    if (MYEMAIL == "")
        $my_email = $_POST['toemail']; // use this line if MYEMAIL is not defined
    else
        $my_email = MYEMAIL;    // Use this one if MYEMAIL is defined
    // =========================================================
    // THE MESSAGE
    $headers = "To: ".$my_email. "\r\n";
    $headers .= "From: ".$email. "\r\n";
    $msg = $name." has submitted a comment:\r\n\r\n";
    $msg .= $comment."\r\n\r\n";
    mail($my_email, $subject, $msg, $headers);
    // MESSAGE TO VISITOR:
    $headers = "To: ".$email. "\r\n"; // this is the email given by the visitor
    $headers .= "From: ".$my_email. "\r\n";
    $subject = "Your message to ".$my_email;
    $msg = "Thank you for contacting us.\r\n\r\n";
    $msg .= "We will endeavour to respond shortly.\r\n\r\n";
    mail($email, $subject, $msg, $headers);
    $txt = "<p align=\"center\">Your email has been sent</p>";
    return($txt);
}
?>
<script type='text/javascript' language='JavaScript'>
function showform(theForm)
{
    var txt = "Form name: " + theForm.name + "\r\n";
    txt += "theForm.elements.length = "+theForm.elements.length+"\r\n";
    for (var i=0; i<theForm.elements.length; i++)
        txt += theForm.elements[i].name + " = " + theForm.elements[i].value + "\r\n";
    alert(txt);
}
function js_validate(theForm)
{
    showform(theForm); // remove when you don't need it
    // Check for name
    var name = theForm.elements['name'].value;
    if (name == "")
    {
        alert ("You must enter your name");
        theForm.elements['name'].focus();
        return true;
    }
    // Check email address
    var email = theForm.elements['email'].value;
    if (echeck(email))
    {
        alert ("You must enter a valid email address");
        theForm.elements['email'].focus();
        return true;
    }
    // Check if subject is not blank
    var sbj = theForm.elements['subject'].value;
    if (sbj == "")
    {
        alert ("You must enter a subject");
        theForm.elements['subject'].focus();
        return true;
    }
    // Check if comment is not blank
    var comt = theForm.elements['comment'].value;
    if (comt == "")
    {
        alert ("You must enter a comment");
        theForm.elements['comment'].focus();
        return true;
    }
    theForm.submit();   // form is ok, we can submit it!
}
// === EMAIL VALIDATION =================================================================================================================================
function echeck(str) 
{
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1)
       return(true);
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
        return(true);
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
        return(true);
    if (str.indexOf(at,(lat+1))!=-1)
        return(true);
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
        return(true);
    if (str.indexOf(dot,(lat+2))==-1)
        return(true);
    if (str.indexOf(" ")!=-1)
        return(true);
    return (false);                 
}
</script>
</head>
<body>
<?php
    if (isset($_POST['submitted']))
    {
        echo (treat_submission());
        unset ($_POST['submitted']);
    }
    else
        echo (show_form());
?>
</body>
</html>


Sziasztok, ezt a formot letöltöttem egy ingyenes oldalról.Ez már átmódosítottam,létrehoztam új textfieldeket stb.
Viszont amikor létre szeretnék hozni egy checkboxot(szerződés elfogadás...) nem tudom beállítani hogy ellenőrizze azt a submit gomb megnyomása utána hogy bepipálták e!Vagy talán még jobb lenne ha addig nemi is működne a Submit gomb!
A php végén van ellenőrző rész ami figyeli az inputokat!

Checkboxot így hoztam létre:
1
$txt .= "<tr><td align=\"center\" ><font color=red><sup>*</sup></font><input type=\"checkbox\" value=\"0\" name=\"agree\"> Elfogadom az általános szerződési feltételeket! </td></tr>";


Köszönöm aki kitudná egészíteni a kódót!