login  Naam:   Wachtwoord: 
Registreer je!
 Forum

form field onclick (Opgelost)

Offline chechu - 24/05/2008 18:57
Avatar van chechuNieuw lid Hey allen,
Ik heb een contactformulier dat eruit ziet als volgt:
  1. <script language="JavaScript" type="text/JavaScript">
  2. function clearDefault(el) {
  3. if (el.defaultValue==el.value) el.value = ""
  4. }
  5. <FORM NAME="form1" METHOD="post" ACTION="contact.php">
  6. <input type="hidden" name="action" value="send">
  7. <INPUT TYPE=TEXT NAME="name" VALUE=" name" onFocus="clearDefault(this)" style="border-top:0px; border-left:0px; border-right:0px; border-bottom: 1px dotted #cc6600; width:150px">
  8. <br>&nbsp;<br>
  9. <INPUT TYPE=TEXT NAME="email" VALUE=" email adress" onFocus="clearDefault(this)" style="border-top:0px; border-left:0px; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
  10. <br>&nbsp;<br>
  11. <TEXTAREA NAME="message" style="border-top:0px; border-left:1px dotted #0066cc; border-right:0px; border-bottom: 1px dotted #0066cc; width:150px; height:63px"> message</TEXTAREA>
  12. <br>&nbsp;<br>
  13. <INPUT TYPE="image" SRC="images/sendarrow.gif" VALUE="send">
  14. <img src="images/clear.gif" onclick="document.getElementById('form1').reset();" style="cursor:pointer"/>
  15. </FORM>


en

  1. <?php
  2.  
  3. if ($_POST["action"] == "send"){
  4.  
  5. if ($_POST[name] != " name" and $_POST[name] != "" and $_POST[email] != " e-mail adress" and $_POST[email] != "" and $_POST[message] != "") {
  6. mail ("info@site.com", "via site",
  7. "
  8. Name: ".$_POST['name']."
  9. E-mail: ".$_POST['email']."
  10. Message: ".$_POST['message']."
  11.  
  12. ",
  13. "From: ".$_POST['name']." <".$_POST['email'].">");
  14.  
  15. $subject = "your message to xx";
  16.  
  17. $msg = "
  18.  
  19. This is an automatically sent email. Please do not reply.
  20.  
  21. Dear $_POST[name],
  22.  
  23. Thanks for your message to xx.
  24. She will get back to you as soon as possible.
  25.  
  26. This was your message:
  27. $_POST[message]
  28. ";
  29.  
  30. mail($_POST[email], $subject, $msg);
  31.  
  32. echo 'Thanks ! Your message has been sent, and you will receive a confirmation mail. <br><br> We will get back to you as soon as we can.<br>&nbsp;<br><br>';
  33.  
  34. }
  35.  
  36. else{
  37. echo '<font color="#FF0000">Please fill in all data!</font><br><br>Your name, email adress and message are mandatory fields.<br><br><a href="contact.html"><font color="#FF0000">[again please]</font></a><br>&nbsp;<br>';
  38. }
  39. }
  40. ?>


Het formulier mag niet verzonde worden als één van volgende gebeurt:
1. Name equals " your name"
2. Name is blank
3. Email equals " your e-mail address"
4. Email is blank
3. Message equals " your message"
5. Message is blank

Wat is er mis met de code ?

3 antwoorden

Gesponsorde links
Offline demich - 24/05/2008 20:07
Avatar van demich Nieuw lid Hallo,

Je moet $_POST["name"] ipv $_POST[name] gebruiken,
name moet je dus tussen aanhalingstekens zetten.
En dit hetzelfde voor $_POST["email"] en $_POST["message"]
Offline chechu - 29/05/2008 20:26
Avatar van chechu Nieuw lid allemaal zo plaatsen ["name"] of ['name'] ?
Offline memar - 30/05/2008 01:00 (laatste wijziging 30/05/2008 01:01)
Avatar van memar Nieuw lid Je kan ook gwn ['name'] gebruiken.
Je kan ook best haken plaatsen wanneer je met AND of OR werkt.
En ipv altijd uit de POST array te werken gebruik je best gewone variabelen. Dit maakt je script korter en overzichtelijker.  
vb:
  1. $name = $_POST['name'];
  2. $email = $_POST['email'];
  3. $message = $_POST['message'];
  4. if (($name) AND ($name != "name") AND ($email) AND ($email != "e-mail adress") AND ($message)) {
  5. ...
  6. }

Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.198s