Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: complicated mail/subscription form

  1. #11
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    But in fact, nothing needs to be stored ? Even if both codes would be mixed on one page, one form, that would be fine.

    So just a few fields to fill in (as my code above) and a few files to attach (like code MJH) in the same form, and I can start. My problem is that I do not know how to "mix" them ...

    I need this urgently, that's why I can be flexible in the start-up form. After that, indeed I will contact a "professional" to have exactly what I need.

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The problem is what you need specifically: any number of attachments (dynamically) and form validation.

    You submit the form, the files are stored (where?), then it validates, finds an error and sends you back to the original page. You could do this where you have a "stored" file, just by filename, with a link to "delete attachment", or you could add new attachments again, but this is complex and might be messy compared to what you want.

    Even to figure out HOW to do this takes a bit of time, and then doing it would take someone fairly experienced with contact forms at least 2 hours to code (maybe a lot more depending on how many "extras" you need, like the dynamic javascript "add an attachment" option).

    If you want the "quick and dirty" version, then just skip validating the form (just refuse incorrect data on the server, so no hacking attempts would work, then send them back to the original, empty form), and allow a specific number of attachments. Maybe one (easiest), or just a list of five attachments (and if they leave all but one blank then there won't be an error-- it just won't do those).

    If you just want to add an attachment option to an existing form, that's a lot more reasonable, but probably still about an hour of work because an existing form has a specific setup that must be modified to add additional behavior.
    This is something like taking a truck that has two seats and trying to add a third in the middle. It's possible, but to make it work well and be safe there's a lot that has to be done. And now if you want it customizable to any number of seats, that's another issue entirely, with its own complexities even just starting at "how can I do that?"
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #13
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    Thanks for your explanation, Daniel.
    I already have this: http://www.portretkunst.be/ZZZ.php, but I would like to have the option that MJH sent included (upload of multiple files posibility), or at least add ten upload fields.

    This is the code I would start from:

    Code:
    <?php
    // Your e-mail adress:
    $mailto = "naam@sitenaam.nl";
    
    # Maximum size of attachment in bytes:
    $max_attach_size = 500000;
    
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>Formmailer</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    </head>
    <body><?php
    /*if (empty($_POST['form_submitted']))
     {
      ?></font><p><font color="#FFFFFF">Please fill out the form:</font></p>
    <font color="#FFFFFF"><?php
     }
    */
     if (isset($_POST["form_submitted"]))
     {
      $name = $_POST['name'];
      $email = $_POST['email'];
      $subject = $_POST['subject'];
      $text = $_POST['text'];
    
      unset($errors);
      if ($email != "" and !preg_match("/^[^@]+@.+\.\D{2,5}$/", $email)) $errors[] = "e-mail address lijkt incorrect";
      if ($text == "") $errors[] = "Geen bericht geplaatst";
      if ($_FILES['probe']['size'] > $max_attach_size) $errors[] = "Bijlage is te groot(".number_format($_FILES['probe']['size']/1000,0,",","")." KB) - maximum size: ".number_format($max_attach_size/1000,0,",","")." KB";
    
      if (empty($errors))
       {
        $text = stripslashes($text);
        $subject = stripslashes($subject);
        if ($name != "") $mail_name=$name; else $mail_name="Unknown";
        if ($subject != "") $mail_subject = $subject; else $mail_subject = "No subject";
        if ($email != "") $mail_email = $email; else $mail_email = "email@unknown.xyz";
        $ip = $_SERVER["REMOTE_ADDR"];
    
        // if attachment, MIME-Mail:
        if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "")
         {
          // read and encode file:
          $datei_content = fread(fopen($_FILES['probe']['tmp_name'],"r"),filesize($_FILES['probe']['tmp_name']));
          $datei_content = chunk_split(base64_encode($datei_content),76,"\n");
          // Boundary:
          $boundary = md5(uniqid(rand()));
          // Mail-Header:
          $mail_header = "From: ".$mail_name." <".$mail_email.">\n";
          $mail_header .= "X-Sender-IP: ".$ip."\n";
          $mail_header .= "MIME-Version: 1.0\n";
          $mail_header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
          $mail_header .= "This is a multi-part message in MIME format.\n";
          // Mail-Text:
          $mail_header .= "--".$boundary;
          $mail_header .= "\nContent-Type: text/plain";
          $mail_header .= "\nContent-Transfer-Encoding: 8bit";
          $mail_header .= "\n\n".$text;
          // Attachment:
          $mail_header .= "\n--".$boundary;
          $mail_header .= "\nContent-Type: ".$_FILES['probe']['type']."; name=\"".$_FILES['probe']['name']."\"";
          $mail_header .= "\nContent-Transfer-Encoding: base64";
          $mail_header .= "\nContent-Disposition: attachment; filename=\"".$_FILES['probe']['name']."\"";
          $mail_header .= "\n\n".$datei_content;
          // End:
          $mail_header .= "\n--".$boundary."--";
          // Sende E-Mail und gebe Fehler bzw. Bestaetigung aus
          if (@mail($mailto,$mail_subject,"",$mail_header)) $sent = true; else $errors[] = "no connection to the mailserver - please try again later";
         }
        // no attachment, normal E-mail:
        else
         {
          $mail_header = "From: ".$mail_name." <".$mail_email.">\n";
          $mail_header .= "X-Sender-IP: $ip\n";
          $mail_header .= "Content-Type: text/plain";
          if (@mail($mailto,$mail_subject,$text,$mail_header)) $sent = true; else $errors[] = "no connection to the mailserver - please try again later";
         }
    
        // copy to sender:
        if (isset($sent) && isset($email) && $email != "" && isset($_POST['copy']))
         {
          if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "") $copy_mail_text = "Copy of the e-mail:\n\n".$text."\n\nAttachment: ".$_FILES['probe']['name']; else $copy_mail_text = "Copy of the e-mail:\n\n".$text;
          $header= "From: ".$mailto."\n";
          $header .= "X-Sender-IP: ".$ip."\n";
          $header .= "Content-Type: text/plain";
          @mail($email, $mail_subject, $copy_mail_text, $header);
         }
       }
     }
    
    if (empty($sent))
     {
      if(isset($errors))
       {
        ?></font><p class="caution"><font color="#FFFFFF">Error:</font></p><ul>
        <font color="#FFFFFF"><?php foreach($errors as $f) { ?></font><li>
        <font color="#FFFFFF"><?php echo $f; ?></li><?php } ?></font></ul>
    <font color="#FFFFFF"><br /><?php
       }
    
      ?></font><form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"><div>
      <p><font color="#FFFFFF"><span class="style2"><font face="Verdana" size="2">
        Naam</font></span><font face="Verdana" size="2"><span class="style2">:</span><br />
        </font>
        </font><font color="#FFFFFF">
        <input name="name" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo ""; ?>" size="25" style="font-family: Verdana; border: 1px dashed #000000" />
        <font face="Verdana" size="2">
        <br />
        <span class="style2">E-mail:</span><br />
        </font>
        </font><font color="#FFFFFF">
        <input name="email" value="<?php if (isset($email)) echo htmlentities(stripslashes($email)); else echo ""; ?>" size="25" style="font-family: Verdana; border: 1px dashed #000000" />
        <font face="Verdana" size="2">
        <br />
        <span class="style2">Onderwerp:</span><br />
        </font>
        </font><font color="#FFFFFF">
        <input name="subject" value="<?php if (isset($subject)) echo htmlentities(stripslashes($subject)); else echo ""; ?>" size="25" style="font-family: Verdana; border: 1px dashed #000000" />
        <font face="Verdana" size="2">
        <br />
        <span class="style2">Bericht:</span><br />
        </font>
        </font><font color="#FFFFFF">
        <textarea name="text" cols="25" rows="7" style="font-family: Verdana; border: 1px dashed #000000"><?php if (isset($text)) echo htmlentities(stripslashes($text)); else echo ""; ?>
        </textarea>
    <font face="Verdana" size="2">
        <br />
        <span class="style2">Bijlagen:</span><br />
        </font>
        </font><font color="#FFFFFF">
        <input type="file" name="probe" value="<?php if (isset($_POST['probe'])) echo htmlentities(stripslashes($_POST['probe'])); else echo ""; ?>" size="16" style="font-family: Verdana; border: 1px dashed #000000"/>
        </font>
      </p>
      </p>
      <p><font face="Verdana"><font color="#FFFFFF"><input type="checkbox" name="copy" value="true" /></font><font size="2" color="#FFFFFF">
        <span class="style2">Kopietje naar jezelf sturen?</span> </font></font>
        <font color="#FFFFFF">
        <input type="submit" name="form_submitted" value="OK - Verzenden" style="font-family: Verdana; border: 1px dashed #000000" /></font><font face="Verdana" size="2" color="#FFFFFF">
        </font> </p>
      </div>
    </form><font color="#FFFFFF"><?php
     }
    else
     {
      if (empty($email)) { ?></font></font><font color="#FFFFFF"> </font>
    <p><font color="#FFFFFF"><b><font face="Verdana" size="1">Bedankt</font></b><font size="1" face="Verdana"><b>!</b><br />
    Je mail is verzonden alleen kan ik je niet terug mailen omdat je geen e-mail 
    adres hebt ingevuld! </font></font></p>
    <font face="Verdana" size="1"><font color="#FFFFFF"><?php }
      else { ?></font></font><font color="#FFFFFF"> </font>
    <p><font color="#FFFFFF"><b><font face="Verdana" size="1">Bedankt</font></b><font size="1" face="Verdana"><b>!</b><br />
    Je bericht is met succes verzonden ik zal zo spoedig mogelijk terug mailen. </font>
    </font></p>
    <font face="Verdana" size="1" color="#FFFFFF"><?php }
     }
    
    ?>
    Last edited by chechu; 01-08-2010 at 08:31 PM.

  4. #14
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    Could anyone be able to add the two codes together, please ?
    Thanks !

  5. #15
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm sorry that I don't really have time to take this on now. But you still need to explain what to do with the conflict between the file uploads and validation. Personally I would split it for better usability but that would not be easier coding.
    "just merging" those would result in the user needing to reupload the files every time it did not validate. Is this acceptable?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •