WEB Drupal: Help creating a block with a custom form

Discussion in 'OT Technology' started by subwoofer, Nov 27, 2009.

  1. subwoofer

    subwoofer OT Supporter

    Joined:
    Aug 28, 2003
    Messages:
    10,966
    Likes Received:
    0
    Location:
    california
    I could not find a module that would let me create a form with custom fields and put it in a block, so I decided to do a little work...

    I created a block with a form.
    Form goes to a page created in drupal with php filter to send the contents of the form as an email, and then redirect the user to thank-you.php.

    The php code is from mail script I have been using for a long time, works with any forms I create.

    I am not sure what to really do, not very proficient in php at all.

    You can view the form at www.consumerag.com, it is on the right.

    Here is the code for the script. Thanks for help in advance ;)
    Code:
    <?php
    
    /* INSTRUCTIONS
     **************
     * 1) Change the 'emailTo' variable (below) from "[email protected] (Your Name)" to your own email and your own name
     * 2) Change the 'emailFrom' variable (below) from "yourdomain.com" to your own domain (no www required)
     * 3) a) Change the 'redirect' variable (below) from "www.yourdomain.com" to your own domain.  
     *    b) Make sure you have a "thank_you.htm" in the root folder of your website
     * 4) Make sure that each of your for elements on the page that submits to this script are named 
     *    ike the following: <input type=text name="INFO__User_Name">
     *    NOTE: You cannot have spaces in the name of the for element.
     *    ie: GOOD element name "INFO__User_Name"
     *        BAD element name "INFO__User Name"
     * 5) Set the "action" of the form to "process_form.php" in the form page that submits to this script
     *    Example: <form method='post' action='process_form.php'>
     * 6) Submit form to make sure all required information gets emailed to you.  If not, then go through steps 4 and 5 again.
     */
    
    // CONFIGURATION SETTINGS 
    $emailTo     = "[email protected]";
    $emailFrom   = "[email protected] (ConsumerAG.com)";
    $subject     = "Inquiry from ConsumerAG Website";
    $redirectURL = "http://consumerag.com/content/11/thank-you.html";
    
    
    // PLACE ALL FIELDS PASSED IN FROM FORM INTO MESSAGE BODY
    foreach ($_POST as $key => $value) {
      $keyInfo = explode("__", $key);
      
      if ($keyInfo[0] == "INFO") {
        $message .= $keyInfo[1].":\n ".$value."\n\n";
      }
    }
    
    // SEND EMAIL
    mail($emailTo, $subject, $message, "From: ".$emailFrom);
    
    // REDIRECT TO SPECIFIED THANK YOU PAGE
    header("Location: $redirectURL");
    
    ?>
     
  2. subwoofer

    subwoofer OT Supporter

    Joined:
    Aug 28, 2003
    Messages:
    10,966
    Likes Received:
    0
    Location:
    california
    Nevermind. Found a module that works correctly. Webform lets me create custom forms. Webform block lets me put them in blocks.

    Just what I wanted. :)
     

Share This Page