SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hardcoding hidden fields into formmail php script

    hello all. i'm going to try to explain my issue as non-confusingly as possible, in the hopes that somebody here will be able to help me!

    all of my forms use the PHPFormmail from http://www.boaddrink.com (if you're not familiar, it's pretty much the same as all the others). however, my company recently started using a new lead management website called Top Producer (or "TP"), and we want our form results to also go to TP to automatically populate the contact info into our account.

    TP uses asp to process form results, so you're supposed to use their asp url for the form action, and include some hidden fields in the form that tell it which account to post to.

    so, i went on the forum at boaddrink.com to ask if it was possible to tell the formmail.php to send the results to that url in addition to the email it already sends out. he (the site admin guy) said: Yes it is possible. You'll have to hardcode the hidden fields in the script but other than that you'll just need to use redirect and redirect_values. (Redirect to point to that .asp file and redirect values so it will send over the values.)

    he also posted a link to the section of his instructions on how to use the redirect and redirect_values fields, here:
    link


    however, he didn't explain how to hardcode the fields in the script. i am not a programmer, or a php expert. the only coding i know is html, and even then i doubt i could build a very good website without the help of a wysiwyg editor. so, obviously, i can't figure out where i'm supposed to hardcode the hidden fields. i posted a response asking him where to do it, but he hasn't responded and time is of the essence!

    so, i will attach the code here, and hope that somebody here can look at it and tell me where i need to hardcode the hidden fields, whatever that even means! i can also post the hidden fields, if necessary.

    thanks in advance to anyone who helps me. your assistance is greatly appreciated!

    -courtney

    PHP Code:
    <?PHP
    define
    ('VERSION','Classic v1.07.2');
    define('MANUAL','http://www.boaddrink.com/projects/phpformmail/readme.php');
    define('CHECK_REFERER'false);

    // +------------------------------------------------------------------------+
    // | PHPFormMail                                                            |
    // | Copyright (c) 1999 Andrew Riley (webmaster@boaddrink.com)              |
    // |                                                                        |
    // | This program is free software; you can redistribute it and/or          |
    // | modify it under the terms of the GNU General Public License            |
    // | as published by the Free Software Foundation; either version 2         |
    // | of the License, or (at your option) any later version.                 |
    // |                                                                        |
    // | This program is distributed in the hope that it will be useful,        |
    // | but WITHOUT ANY WARRANTY; without even the implied warranty of         |
    // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the           |
    // | GNU General Public License for more details.                           |
    // |                                                                        |
    // | You should have received a copy of the GNU General Public License        |
    // | along with this program; if not, write to the Free Software            |
    // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, |
    // | USA.                                                                   |
    // |                                                                        |
    // +------------------------------------------------------------------------+
    // |                                                                        |
    // | If you run into any problems, pleas read the readme_formmail.txt.        |
    // | If that does not help, check out http://www.boaddrink.com.             |
    // |                                                                        |
    // | For more info, please visit http://www.boaddrink.com or read the       |
    // | readme file included.                                                  |
    // +------------------------------------------------------------------------+
    // |                                                                        |
    // | Value array fix by: Konrad Maqestieau                                  |
    // | check_recipients reset() fix by: Don                                   |
    // | servertime_offset code by: desolate                                    |
    // |                                                                        |
    // +------------------------------------------------------------------------+

    // To change the address the e-mail comes from use define('FROM', 'Example Name <email@example.com>');
    define('FROM''<webmaster@newhomeconnection.com>');

    $referers = array('www.example.com''example.com');

    // $recipient_array format is $recipient_array = array('sometext'=>'email@example.com','asdf'=>'email2@example.com');
    $recipient_array = array('me' =>'webmaster@newhomeconnection.com');

    $valid_env = array('REMOTE_HOST''REMOTE_ADDR''REMOTE_USER''HTTP_USER_AGENT');

    // +------------------------------------------------------------------------+
    // | STOP EDITING! The only two required variables that need to be updated  |
    // | are $referers and $valid_env                                           |
    // +------------------------------------------------------------------------+

    $errors $fieldname_lookup = array();
    $invis_array = array('recipient','subject','required','redirect',
                 
    'print_blank_fields','env_report','sort',
                 
    'missing_fields_redirect','title','bgcolor',
                 
    'text_color','link_color','alink_color',
                 
    'vlink_color','background','subject','title',
                 
    'link','css','return_link_title',
                 
    'return_link_url','recipient_cc','recipient_bcc',
                     
    'priority','redirect_values','hidden','alias',
             
    'mail_newline''gmt_offset''alias_method',
             
    'subject_prefix');

    /****************************************************************
     * fake_in_array() is only used in PHP3 since PHP4 has a native    *
     * in_array.  Depending on what version of PHP you are running    *
     * the script will determine what is the best function to run     *
     * --- THER IS NO LONGER ANY REASON TO DELETE THIS FUNCTION ---    *
     * Function renamed in 1.04.0                    *
     ****************************************************************/

    function fake_in_array($needle$haystack)
    {
        
    $found false;
        while (list(
    $key,$val) = each ($haystack)) {
            if (
    $needle == $val)
                
    $found true;
        }
        return 
    $found;
    }

    /****************************************************************
     * check_referer() breaks up the enviromental variable        *
     * HTTP_REFERER by "/" and then checks to see if the second    *
     * member of the array (from the explode) matches any of the    *
     * domains listed in the $referers array (declaired at top)    *
     ****************************************************************/

    function check_referer($referers)
    {
        global 
    $errors;
        if (
    count($referers)) {
            if (
    getenv('HTTP_REFERER')) {
                
    $temp explode('/'getenv('HTTP_REFERER'));
                
    $found false;
                while (list(,
    $stored_referer) = each($referers)) {
                    if (
    eregi('^' $stored_referer '$'$temp[2]))
                        
    $found true;
                }
                if (!
    $found) {
                    
    $errors[] = '1|You are coming from an unauthorized domain.  Please read the manual section titled &quot;<a href="' MANUAL '#setting_up" target="_blank">Setting Up the PHPFormMail Script</a>&quot;.';
                    
    error_log('[PHPFormMail] Illegal Referer. (' getenv('HTTP_REFERER') . ')'0);
                }
                return 
    $found;
            } else {
                
    $errors[] = '0|Sorry, but I cannot figure out who sent you here.  Your browser is not sending an HTTP_REFERER.  This could be caused by a firewall or browser that removes the HTTP_REFERER from each HTTP request you submit.';
                
    error_log('[PHPFormMail] HTTP_REFERER not defined. Browser: ' getenv('HTTP_USER_AGENT') . '; Client IP: ' getenv('REMOTE_ADDR') . '; Request Method: ' getenv('REQUEST_METHOD') . ';'0);
                return 
    false;
            }
        } else {
            
    $errors[] = '1|There are no referers defined.  All submissions will be denied.  Please read the manual section titled &quot;<a href="' MANUAL '#setting_up" target="_blank">Setting Up the PHPFormMail Script</a>&quot;.';
            
    error_log('[PHPFormMail] You have no referers defined.  All submissions will be denied.'0);
            return 
    false;
        }
    }

    /****************************************************************
     * check_recipients() breaks up the recipents e-mail addresses    *
     * and then crossrefrences the domains that are legal referers    *
     * Function added in 1.3.1                                      *
     ****************************************************************/

    function check_recipients($recipient_list)
    {
        global 
    $errors$referers;
        
    $recipients_ok true;
        
    $recipient_list explode(','$recipient_list);
        while (list(,
    $recipient) = each($recipient_list)) {
            
    $recipient_domain false;
            
    $recipient trim($recipient);
            
    reset($referers);
            while ((list(,
    $stored_domain) = each($referers)) && ($recipient_domain == false)) {
                if (
    eregi('^[_\.a-z0-9-]*@' $stored_domain '$'$recipient))
                    
    $recipient_domain true;
            }
            if (
    $recipient_domain == false) {
                
    $recipients_ok false;
                
    error_log('[PHPFormMail] Illegal Recipient: ' $recipient ' from ' getenv('HTTP_REFERER'), 0);
            }
        }
        if (!
    $recipients_ok)
            
    $errors[] = '1|You are trying to send mail to a domain that is not in the allowed recipients list.   Please read the manual section titled &quot;<a href="' MANUAL '#setting_up" target="_blank">Setting Up the PHPFormMail Script</a>&quot;.';
        return 
    join(','$recipient_list);
    }

    /****************************************************************
     * map_recipients() takes the array and maps them to the proper *
     * e-mail addresses from $recipient_array.  If this function is *
     * called then the e-mail addresses are not checked against the *
     * referer array.                                               *
     * Function added in 1.7.0                                      *
     ****************************************************************/

    function map_recipients($recipient_list)
    {
        global 
    $errors$recipient_array;
        
    $recipients_ok true;
        
    $recipient_list explode(',',$recipient_list);
        while (list(,
    $val) = each($recipient_list)){
            
    $val trim($val);
            if(isset(
    $recipient_array[$val]))
                
    $output[] = $recipient_array[$val];
            else
                
    $recipients_ok false;
        }
        if (!
    $recipients_ok)
            
    $errors[] = '1|You are trying to send mail to an address that is not listed in the recipient array.';
        if (isset(
    $output))
            return 
    join(','$output);
        else
            return 
    null;
    }

    /****************************************************************
     * decode_vars() is used to assign all of the variables passed    *
     * into the form to a generic variable.  Allthough there are    *
     * two official form actions, POST and GET, I decided to use    *
     * this variable method so if more actions are invented, I    *
     * wouldn't have to change anything.                *
     *                                *
     * In the first line, the request methood is assigned to    *
     * $request with HTTP_ and _VARS appended to it.        *
     * In the second line uses PHPs variable variable.        *
     * It's basically addressing the variable $HTTP_POST_VARS or    *
     * $HTTP_GET_VARS and returning that.  Read more about        *
     * variable variables in the PHP documentation.            *
     ****************************************************************/

    function decode_vars()
    {
        if (isset(
    $_REQUEST))
            
    $request '_' getenv('REQUEST_METHOD');
        else
            
    $request 'HTTP_' getenv('REQUEST_METHOD') . '_VARS';
        global $
    $request;
        if (
    count($$request) > 0) {
            while (list(
    $key$val) = each($$request)) {
                if (
    is_array($val))
                    
    $val implode(', ',$val);
                
    $output[$key] = stripslashes($val);
            }
            return 
    $output;
        } else
            return array();
    }


    /****************************************************************
     * error() is our generic error function.            *
     * When called, it checks for errors in the $errors array and    *
     * depending on $form["missing_fields_redirect"] will either    *
     * print out the errors by calling the function output_html()    *
     * or it will redirect to the location specified in        *
     * $form["missing_fields_redirect"].                *
     ****************************************************************/

    function error()
    {
        global 
    $form$natural_form$errors;
        if (isset(
    $form['missing_fields_redirect'])) {
            if (isset(
    $form['redirect_values']))
                
    header('Location: ' $form['missing_fields_redirect'] . '?' getenv('QUERY_STRING') . "\r\n");
            else
                
    header('Location: ' $form['missing_fields_redirect'] . "\r\n");
        } else {
            if(!isset(
    $form['title']))
                
    $form['title'] = 'PHPFormMail - Error';
            
    $output "<h1>The following errors were found:</h1>\n<ul>\n";
            
    $crit_error 0;
            while (list(,
    $val) = each ($errors)) {
                list(
    $crit,$message) = explode('|',$val);
                
    $output .= '  <li>' $message "</li>\n";
                if (
    $crit == 1)
                    
    $crit_error 1;
            }
            
    $output .= "</ul>\n";
            if (
    $crit_error == 1)
                
    $output .=  "<div class=\"crit\">PHPFormMail has experienced errors that must be fixed by the webmaster. Mail will NOT be sent until these issues are resolved.  Once these issues are resolved, you will have to resubmit your form to PHPFormMail for the mail to be sent.</div><div class=\"returnlink\">Please use the <a href=\"javascript: history.back();\">back</a> button to return to the site.</div>\n";
            else
                
    $output .=  "<div class=\"returnlink\">Please use the <a href=\"javascript: history.back();\">back</a> button to correct these errors.</div>\n";
            
    output_html($output);
        }
    }

    /****************************************************************
     * check_required() is the function that checks all required    *
     * fields to see if they are empty or match the provided regex    *
     * string (regex checking added in 1.02.0).            *
     *                                *
     * Should a required variable be empty or not match the regex    *
     * pattern, a error will be added to the global $errors array.    *
     ****************************************************************/

    function check_required()
    {
        global 
    $form$errors$invis_array$fieldname_lookup;
        
    $problem true;
        if ((!isset(
    $form['recipient'])) && (!isset($form['recipient_bcc']))) {
            
    $problem false;
            
    $errors[] = '1|There is no recipient to send this mail to.  Please read the manual section titled &quot;<a href="' MANUAL '#recipient" target="_blank">Form Configuration - Recipient</a>&quot;.';
            
    error_log('[PHPFormMail] There is no recipient defined from ' getenv('HTTP_REFERER'), 0);
        }
        if (isset(
    $form['required'])) {
            
    $required split(','$form['required']);
            while (list(,
    $val) = each($required)) {
                
    $val trim($val);
                
    $regex_field_name $val '_regex';
                if ((!isset(
    $form[$val])) || (isset($form[$val]) && (strlen($form[$val]) < 1))) {
                    
    $problem false;
                    if (isset(
    $fieldname_lookup[$val]))
                        
    $field $fieldname_lookup[$val];
                    else
                        
    $field $val;
                    
    $errors[] = '0|Required value (<b>' $field '</b>) is missing.';
                } else if (isset(
    $form[$regex_field_name])) {
                    if (!
    eregi($form[$regex_field_name],$form[$val])) {
                        
    $problem false;
                        
    $errors[] = '0|Required value (<b>' $fieldname_lookup[$val] . '</b>) has an invalid format.';
                    }
                    
    $invis_array[] = $regex_field_name;
                }
            }
        }
        return 
    $problem;
    }


    /****************************************************************
     * sort_fields() is responsable for sorting all fields in $form    *
     * depending $form["sort"].                    *
     * There are three main sort methods: alphabetic, reverse    *
     * alphabetic, and user supplied.                *
     *                                *
     * The user supplied method is formatted "order:name,email,etc".*
     * The text "order" is required and the fields are comma    *
     * sepperated. ("order" is legacy from the PERL version.) If    *
     * the user supplied method leaves fields out of the comma    *
     * sepperated list, the remaining fields will be appended to    *
     * the end of the orderd list in the order they appear in the    *
     * form.                            *
     * Function added in 1.02.0                    *
     ****************************************************************/

    function sort_fields()
    {
        global 
    $form;
        switch (
    $form['sort']) {
            case 
    'alphabetic':
            case 
    'alpha':        ksort($form);
                        break;
            case 
    'ralphabetic':
            case 
    'ralpha':        krsort($form);
                        break;
            default:        if (
    $col strpos($form['sort'],':')) {
                            
    $form['sort'] = substr($form['sort'],($col 1));
                            
    $temp_sort_arr explode(','$form['sort']);
                            for(
    $x 0$x count($temp_sort_arr); $x++) {
                                
    $out[$temp_sort_arr[$x]] = $form[$temp_sort_arr[$x]];
                                unset(
    $form[$temp_sort_arr[$x]]);
                            }
                            
    $form array_merge($out,$form);
                        }
        }
        return 
    true;
    }


    /****************************************************************
     * alias_fields() creates a lookup array so we can use Aliases    *
     * for the field names.     If a alias is not available, the    *
     * lookup array is filled with the form field's name        *
     * Function added in 1.05.0                    *
     ****************************************************************/

    function alias_fields()
    {
        global 
    $form$fieldname_lookup;
        while (list(
    $key,) = each($form)) {
            
    $fieldname_lookup[$key] = $key;
        }
        
    reset($form);
        if (isset(
    $form['alias'])) {
            
    $aliases explode(','$form['alias']);
            while (list(,
    $val) = each($aliases)) {
                
    $temp explode('='$val);
                
    $fieldname_lookup[trim($temp[0])] = trim($temp[1]);
            }
        }
        return 
    true;
    }


    /****************************************************************
     * send_mail() the function that parses the data into SMTP    *
     * format and sends the e-mail.                    *
     ****************************************************************/

    function send_mail()
    {
        global 
    $form$invis_array$valid_env$fieldname_lookup$errors;
        
        
    $email_replace_array "\r|\n|to:|cc:|bcc:";
        
        if (!isset(
    $form['subject']))
                
    $form['subject'] = 'WWW Form Submission';
        if (isset(
    $form['subject_prefix']))
                
    $form['subject'] = $form['subject_prefix'] . $form['subject'];
        if (!isset(
    $form['email']))
                
    $form['email'] = 'email@example.com';
        
        switch (
    $form['mail_newline']) {
            case 
    2:        $mail_newline "\r";
                    break;
            case 
    3:        $mail_newline "\r\n";
                    break;
            default:    
    $mail_newline "\n";
        }
        
        if (isset(
    $form['gmt_offset']) && ereg('^(\\-|\\+)?([0-9]{1}|(1{1}[0-2]{1}))$'$form['gmt_offset'])) {
            
    $mkseconds mktime(gmdate('H') + $form['gmt_offset']);
            
    $mail_date gmdate('F jS, Y'$mkseconds) . ' at ' gmdate('h:iA'$mkseconds) . ' (GMT ' $form['gmt_offset'] . ').';
        } else
            
    $mail_date date('F jS, Y') . ' at ' date('h:iA (T).');
        
        if (isset(
    $form['realname']))
            
    $realname eregi_replace($email_replace_array,'',$form['realname']);
        elseif (isset(
    $form['firstname']) || isset($form['lastname']))
            
    $realname eregi_replace($email_replace_array,'',trim($form['firstname'] . ' ' $form['lastname']));

        
    $mailbody 'Below is the result of your feedback form.  It was submitted by' $mail_newline;
        if (isset(
    $realname))
            
    $mailbody.= $realname ' (' $form['email'] . ') on ' $mail_date $mail_newline $mail_newline;
        else
            
    $mailbody.= $form['email'] . ' on ' $mail_date $mail_newline $mail_newline;

        
    reset($form);
        
        while (list(
    $key,$val) = each($form)) {
            if ((!
    in_array($key,$invis_array)) && ((isset($form['print_blank_fields'])) || ($val))) {
                    if((
    $form['alias_method'] == 'email') || ($form['alias_method'] == 'both'))
                        
    $mailbody .= $fieldname_lookup[$key];
                    else
                        
    $mailbody .= $key;
                    
    $mailbody .= ': ' $val $mail_newline;
            }
        }
        
        if (isset(
    $form['env_report'])) {
            
    $temp_env_report explode(','$form['env_report']);
            
    $mailbody .= $mail_newline $mail_newline '-------- Env Report --------' $mail_newline;
            while (list(,
    $val) = each($temp_env_report)) {
                if (
    in_array($val,$valid_env))
                        
    $mailbody .= eregi_replace($email_replace_array,'',$val) . ': ' eregi_replace($email_replace_array,'',getenv($val)) . $mail_newline;
            }
        }

        if (!isset(
    $form['recipient']))
            
    $form['recipient'] = '';

        
    // Append lines to $mail_header that you wish to be
        // added to the headers of the e-mail. (SMTP Format
        // with newline char ending each line)

        
    $mail_header 'Return-Path: ' eregi_replace($email_replace_array,'',$return_path) . $mail_newline;
        if (
    FROM != null)
            
    $mail_header .= 'From: ' FROM $mail_newline;
        
    $mail_header .= 'Reply-to: ';
        if (isset(
    $realname))
            
    $mail_header .= $realname ' <' eregi_replace($email_replace_array,'',$form['email']) . '>' $mail_newline;
        else
            
    $mail_header .= eregi_replace($email_replace_array,'',$form['email']) . $mail_newline;
        if (isset(
    $form['recipient_cc']))
            
    $mail_header .= 'Cc: ' eregi_replace($email_replace_array,'',$form['recipient_cc']) . $mail_newline;
        if (isset(
    $form['recipient_bcc']))
            
    $mail_header .= 'Bcc: ' eregi_replace($email_replace_array,'',$form['recipient_bcc']) . $mail_newline;
        if (isset(
    $form['priority']))
            
    $mail_header .= 'X-Priority: ' ereg_replace($email_replace_array,'',$form['priority']) . $mail_newline;
        else
            
    $mail_header .= 'X-Priority: 3' $mail_newline;
        
    $mail_header .= 'X-Mailer: PHPFormMail ' VERSION ' (http://www.boaddrink.com)' $mail_newline;
        
    $mail_header .= 'X-Sender-IP: ' eregi_replace($email_replace_array,'',getenv('REMOTE_ADDR')) . $mail_newline;
        
    $mail_header .= 'X-Referer: ' eregi_replace($email_replace_array,'',getenv('HTTP_REFERER')) . $mail_newline;
        
        
    $form['subject'] = eregi_replace($email_replace_array,'',$form['subject']);
        
        if (
    eregi("MIME-|Content-|boundary"$mail_header $mailbody $form['subject']) == 0) {
            
    $mail_header .= 'Content-Type: text/plain; charset=utf-8' $mail_newline;
            
    $mail_status mail(eregi_replace($email_replace_array,'',$form['recipient']), $form['subject'], $mailbody$mail_header);
            if (!
    $mail_status) {
                
    $errors[] = '1|Message could not be sent due to an error while trying to send the mail.';
                
    error_log('[PHPFormMail] Mail could not be sent due to an error while trying to send the mail.');
            } else {
                
    error_log('[PHPFormMail] Normal e-mail sent from IP ' getenv('REMOTE_ADDR'));
            }
        } else {
                
    $mail_status true;
                
    error_log('[PHPFormMail] Injection characters found from IP ' getenv('REMOTE_ADDR') . '. Silently dropped');
        }
        return 
    $mail_status;
    }


    /****************************************************************
     * output_html() is used to output all HTML to the browser.    *
     * This function is called if there is an error or for the    *
     * "Thank You" page if neither are declaired as redirects.    *
     *                                *
     * While called output_html() it actually outputs valid XHTML    *
     * 1.0 documents.                        *
     * Function added in 1.02.0                    *
     ****************************************************************/

    function output_html($body)
    {
        global 
    $form;
        
        
    $bgcolor    = isset($form['bgcolor']) ? ('background-color: ' htmlspecialchars($form['bgcolor']) . ';') : ('background-color: #FFF;');
        
    $background = isset($form['background']) ? ('background-image: url(' htmlspecialchars($form['background']) . ');') : NULL;
        
    $text_color    = isset($form['text_color']) ? ('color: ' htmlspecialchars($form['text_color']) . ';') : ('color: #000;');
        
    $link_color    = isset($form['link_color']) ? ('color: ' htmlspecialchars($form['link_color']) . ';') : NULL;
        
    $alink_color    = isset($form['alink_color']) ? ('color: ' htmlspecialchars($form['alink_color']) . ';') : NULL;
        
    $vlink_color    = isset($form['vlink_color']) ? ('color: ' htmlspecialchars($form['vlink_color']) . ';') : NULL;
        
        print 
    "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
        print 
    "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-US\" lang=\"en-US\">\n";
        print 
    "<head>\n";
        print 
    "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
        print 
    "  <meta name=\"robots\" content=\"noindex,nofollow\" />\n";
        print 
    "  <title>" htmlspecialchars($form['title']) . "</title>\n";
        print 
    "  <style type=\"text/css\">\n";
        print 
    "    BODY {" trim($bgcolor ' ' $text_color ' ' $background) . "}\n";
        if (isset(
    $link_color))
            print 
    "    A {" $link_color "}\n";
        if (isset(
    $alink_color))
            print 
    "    A:active {" $alink_color "}\n";
        if (isset(
    $vlink_color))
            print 
    "    A:visited {" $vlink_color "}\n";
        print 
    "    h1 {font-size: 14pt; font-weight: bold; margin-bottom: 20pt}\n";
        print 
    "    .crit {font-size: 12pt; font-weight: bold; color: #F00; margin-bottom: 10pt;}\n";
        print 
    "    .returnlink {font-size: 12pt; margin-top: 20pt; margin-bottom: 20pt;}\n";
        print 
    "    .validbutton {margin-top: 20pt; margin-bottom: 20pt;}\n";
        print 
    "  </style>\n";
        if (isset(
    $form['css']))
            print 
    "  <link rel=\"stylesheet\" href=\"" htmlspecialchars($form['css']) . "\">\n";
        print 
    "</head>\n\n";
        print 
    "<body>\n";
        print 
    "<!-- PHPFormMail from http://www.boaddrink.com -->\n";
        print 
    $body;
        print 
    "<div class=\"validbutton\"><a href=\"http://validator.w3.org/check/referer\" target=\"_blank\"><img src=\"http://www.w3.org/Icons/valid-xhtml10\" style=\"border:0;width:88px;height:31px\" alt=\"Valid XHTML 1.0!\" /></a></div>\n";
        print 
    "</body>\n";
        print 
    "</html>";
    }


    $form decode_vars();

    if (
    count($form) > 0) {
        
        
    // PFMA remove if block
        // Determine (based on the PHP version) if we should use the native
        // PHP4 in_array or the coded fake_in_array

        
    if (phpversion() >= '4.0.0')
            
    $in_array_func 'in_array';
        else
            
    $in_array_func 'fake_in_array';

        if(
    $use_field_alias = isset($form['alias']))
            
    alias_fields();
        
        if(
    CHECK_REFERER == true)
            
    check_referer($referers);
        else
            
    error_log('[PHPFormMail] HTTP_REFERER checking is turned off.  Referer: ' getenv('HTTP_REFERER') . '; Client IP: ' getenv('REMOTE_ADDR') . ';'0);

        
    // This is used for another variable function call
        
    if ((count($recipient_array) > 0) == true)
            
    $recipient_function 'map_recipients';
        else
            
    $recipient_function 'check_recipients';
        
        if (isset(
    $form['recipient']))
            
    $form['recipient'] = $recipient_function($form['recipient']);
        if (isset(
    $form['recipient_cc']))
            
    $form['recipient_cc'] = $recipient_function($form['recipient_cc']);
        if (isset(
    $form['recipient_bcc']))
            
    $form['recipient_bcc'] = $recipient_function($form['recipient_bcc']);
        
        
    check_required();
        
        if (!
    $errors) {

            if (isset(
    $form['sort']))
                
    sort_fields();

            if (isset(
    $form['hidden'])) {
                
    // PFMA REMOVE 1
                
    $form['hidden'] = str_replace(' '''$form['hidden']);
                
    $form['hidden'] = explode(','$form['hidden']);
                
    // PFMA ADD $form['hidden'] = array_map('trim', $form['hidden']);
            
    }

            if (
    send_mail()) {
                if (isset(
    $form['redirect'])) {
                    if (isset(
    $form['redirect_values']))
                        
    header('Location: ' $form['redirect'] . '?' getenv('QUERY_STRING') . "\r\n");
                    else
                        
    header('Location: ' $form['redirect'] . "\r\n");
                } else {
                    if (!isset(
    $form['title']))
                        
    $form['title'] = 'PHPFormMail - Form Results';
                    
    $output "<h1>The following information has been submitted:</h1>\n";
                    
    reset($form);
                    while (list(
    $key,$val) = each($form)) {
                        if ((!
    $in_array_func($key,$invis_array)) && ((isset($form['print_blank_fields'])) || ($val))) {
                            
    $output .= '<div class="field"><b>';
                            if((
    $use_field_alias) && ($form['alias_method'] != 'email'))
                                
    $output .= htmlspecialchars($fieldname_lookup[$key]);
                            else
                                
    $output .= htmlspecialchars($key);
                            if ((isset(
    $form['hidden'])) && ($in_array_func($key,$form['hidden'])))
                                
    $output .= ":</b> <i>(hidden)</i></div>\n";
                            else
                                
    $output .= ':</b> ' nl2br(htmlspecialchars(stripslashes($val))) . "</div>\n";
                        }
                    }
                    if (isset(
    $form['return_link_url']) && isset($form['return_link_title']))
                        
    $output .= '<div class="returnlink"><a href="' $form["return_link_url"] . '">'$form["return_link_title"] . "</a></div>\n";
                    
    output_html($output);
                }
            }
        }
    } else {
        
    $errors[] = '0|Nothing was sent by a form. (No data was sent by POST or GET method.)  There is nothing to process here.';
        
    error_log('[PHPFormMail] No data sent by POST or GET method. (' getenv('HTTP_REFERER') . ')'0);
    }

    if (
    count($errors) > 0)
        
    error();

    ?>

  2. #2
    SitePoint Addict Robert_2006's Avatar
    Join Date
    Jun 2006
    Location
    Tarpon Springs Fl.
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried to read through that file but evertime I cut the text from the box all the line breaks are gone. I end up with one really long line. Try posting the file as a txt attachment. I don't think anyone want to read through the file and fix the line breaks before they read it

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    hidden inputs

    The hidden inputs do not go anywhere into the rather llengthy PHP file you posted, but instead, go into the HTML form.
    <input type="hidden" name="redirect_values" value="true">
    will go into the form you are using. eg.
    HTML Code:
    <form action='whatever_file' method='post'>
    <input type='text' name='email' ... />
    //Hidden inputs
    ....
    </form>

  4. #4
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the responses!

    first, i know that the hidden fields have to go into the form itself, but according to the guy who created the script, i also have to hardcode them into the script. although he didn't explain why, i tend to believe him, because so far just doing the redirect and redirect_values isn't working. it may be worth noting that in his instructions for the redirect_values field, it says you have to use the get method, instead of post. if i do that, after you submit the form it goes to my formmail url with all of the fields in it (as part of the url), and we don't get the email or the results posted in our TP account. and if i change it back to post, it redirects to the asp url, but it's a blank page instead of the confirmation, and we get an email but still no results in our TP account.

    so, as you suggested, Robert, i have attached the php as a text file. and i'll also include the code for my test form, just in case maybe i'm putting in the hidden fields wrong or something.

    thanks again for the help!

    HTML Code:
    <form action="http://www.newhomeconnection.com/forms/fm-test.php" method="get" name="form"><input type="hidden" name="redirect_values" value="true"><input type="hidden" name="recipient" value="me"><input name="subject" type="hidden" value="Test"><input type="hidden" name="redirect" value="https://www.topproduceronline.com/LeadToolkit.asp"><INPUT TYPE="HIDDEN" NAME="MLS_Agent_ID" ID="MLS_Agent_ID"  STYLE="WIDTH: 75.0&#37;;" VALUE="<% writeSafeValue( "MLS_Agent_ID" ); %>">
    	<INPUT TYPE="HIDDEN" NAME="MLS_Office_ID" ID="MLS_Office_ID"  STYLE="WIDTH: 75.0%;" VALUE="<% writeSafeValue( "MLS_Office_ID" ); %>">
    	<INPUT TYPE="HIDDEN" NAME="MLS_Number" ID="MLS_Number"  STYLE="WIDTH: 75.0%;" VALUE="<% writeSafeValue( "MLS_Number" ); %>">
    	<INPUT TYPE="HIDDEN" NAME="SUBSOURCE" ID="SUBSOURCE"  STYLE="WIDTH: 75.0%;" VALUE="<% writeSafeValue( "SUBSOURCE" ); %>">
    	<!-- NOTE: The SUBSOURCE field is associated with the Inquiry form field -->
    	<INPUT TYPE="HIDDEN" NAME="PAGEID" VALUE="TkhDQWRtaW4=">
    	<INPUT TYPE="HIDDEN" NAME="SOURCE" VALUE="Test Form">
    	<INPUT TYPE="HIDDEN" NAME="MSG_SUCCESS" VALUE="Thanks! We will respond to your request as soon as possible. </span> </p>
          a href='javascript:goback(-2)'>Click Here to Go Back</a>">
    	<INPUT TYPE="HIDDEN" NAME="MSG_FAILURE" VALUE="<P><FONT face=Arial size=4><STRONG>Your inquiry has not been sent. The server may be busy, or an unexpected problem has occurred. Please try again. If the problem persists, please email me directly at <a HREF=mailto:forsale@newhomeconnection.com>forsale@newhomeconnection.com</a></STRONG></font><br><br><a href=javascript:history.go(-1)>Click here to return to the previous page</a>">
    	<INPUT TYPE="HIDDEN" NAME="URL_SUCCESS" VALUE="">
    	<INPUT TYPE="HIDDEN" NAME="ASSIGNED_TO" VALUE="{1B7E04EC-9C64-4402-B234-6B71BBDB0DEF}">
      <table border="0" cellpadding="2">
        <tr>
          <td><div align="right">First Name: </div></td>
          <td><input type="text" name="FIRST_NAME" />
          </td>
        </tr>
        <tr>
          <td align="right">Last 
            Name: </td>
          <td><input type="text" name="LAST_NAME
    " />
          </td>
        </tr>
        <tr>
          <td><div align="right">Email:(required) </div></td>
          <td><input type="text" name="EMAIL
    " />
          </td>
        </tr>
        <tr>
          <td><div align="right">Address:</div></td>
          <td><input type="text" name="STREET_NAME
    " />
          </td>
        </tr>
        <tr>
          <td><div align="right">City:</div></td>
          <td><input type="text" name="CITY
    " />
          </td>
        </tr>
        <tr>
          <td><div align="right">State:
            <input type="text" name="STATE" size="4" />
          </div></td>
          <td> Zip:
            <input type="text" name="ZIP" size="8" />
          </td>
        </tr>
        <tr>
          <td><div align="right">Home Phone:</div></td>
          <td><input name="PHONE_AREA_CODE
    " type="text" size="3" maxlength="3" />
            <input name="PHONE_LOCAL_CODE
    " type="text" size="3" maxlength="3" />
            <input name="PHONE_NUMBER
    2" type="text" size="4" maxlength="4" /></td>
        </tr>
      </table>
      <table width="80%" border="0">
        <tr>
          <td width="33%"><script language="JavaScript" src="foil.js" type="text/javascript"></script>
              <noscript>
            Please type  'orange' here:</td>
          <td width="67%"><input name='foil' />
              </noscript></td>
        </tr>
      </table>
      <p>
        <input type="submit" name="Submit" value="Submit" />
      </p>
      </form>
    </body>
    </html>
    Last edited by Ingoal; Jun 17, 2007 at 07:37.

  5. #5
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    new formmail text

    i posted the wrong formmail. there's not much difference, but it might matter. so here's the right one!
    Attached Files Attached Files

  6. #6
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so....no help, huh?

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    form mail mod

    I didn't forget about you, just been a bit busy to tear apart a rather lengthy script. I was hoping the author might have gotten back to you. I'll look into it a bit more than my previous "quick scan" when I get a chance.

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    form mail

    The comments are mine.
    PHP Code:
    if (send_mail()) { /* if the send_mail function successfully sends the email */
      
    if (isset($form['redirect'])) { /* if there's a hidden input w/ the redirect url */
        
    if (isset($form['redirect_values'])) /* if hidden input has value of true */
          
    header('Location: ' $form['redirect'] . '?' getenv('QUERY_STRING') . "\r\n"); /* add form vars to url as GET vars -> vals */
        
    else  /* if no hidden input w/ value of true */
          
    header('Location: ' $form['redirect'] . "\r\n"); /* just redirect w/ no GET vars */ 
    Thus if you have the 2 hidden inputs in your form
    HTML Code:
    <input type="hidden" name="redirect" value="http://your.host.com/to/file.html">
    <input type="hidden" name="redirect_values" value="true">
    the form's values, if the email is succesfully sent, will go to the file specified in the redirect input.
    Quote Originally Posted by wonderpance
    have to use the get method, instead of post. if i do that, after you submit the form it goes to my formmail url with all of the fields in it (as part of the url), and we don't get the email or the results posted in our TP account. and if i change it back to post, it redirects to the asp url, but it's a blank page instead of the confirmation, and we get an email but still no results in our TP account.
    From what I can tell, the header-location line won't run unless the email is sent. Are you in the recipient_cc or recipient_bcc form fields?

  9. #9
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much! i really appreciate your help. the other guy still hasn't gotten back to me. which makes me wonder why he has a forum in the first place!

    to answer your last question, i don't think i have anything in either of those recipient fields.

    but i'm going to try what you gave me, and see what it does.

    thanks again!

  10. #10
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i've finally had a chance to get back to this project. i can't seem to figure out where i need to put that php code!

    could you please tell me around which line in the formmail i need to insert that code?

    thanks again!

  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    formmail

    The PHP code I posted is already in the file, I only added comments to help explain the logic. I admit I may be missing something important regarding what you're trying to do, but as far as I can tell, you only need to add the hidden "redirect" and "redirect_values" inputs into an "action = get" form and you should be all set.
    If this is not the case, please clarify the scenario a bit more.

  12. #12
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh, ok. i get it now! i suppose what i was trying to do is figure out where to "hardcode" the hidden fields (the ones i have to put in my forms that tell it which account to post to on that other website) inside the php. because that's what the guy who wrote it said i'd have to do. i'm beginning to think he's full of crap!

    then again, i think maybe it's that asp url that's causing the problem. seems like it interferes with the redirect. i was just messing around trying a few things, and one thing i tried was just having it go to the asp and then redirecting to a thanks page, but it doesn't redirect. so maybe that's part of the problem.

    but i'm giving up on this. for now, at least. we actually came up with a different solution that's working well for the most part. my associate wrote a javascript that sends the results to both places, and it works except in Firefox where it only sends the results to one place.

    i posted on another forum that i frequent asking for advice regarding why it won't do both functions in Firefox. and one person responded basically saying that i shouldn't use javascript, without giving any explanation as to why.

    you seem to know a lot. what are your thoughts, if you don't mind me asking?

  13. #13
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    formmail

    As I understand it, the formmail script sends an email and displays a thank you message. If you change the redirect, it should send the email and the page specified by the redirect will be responsible for the thank you message (and any other processing). I guessing that you are trying to have the formmail script handle the "other processing", but that most likely the redirect page, in this case the asp file, should be doing the "heavy lifting".
    As for relying on javascript, IMHO it is great for enhancing a page, but should be unobtrusive and degrade gracefully in browsers without javascript. If you turn off javascript in your browser and the form won't work at least in a less enhanced way, then it's possible some of your users (estimates vary, but 10% sounds probable) will have a less than satisfactory experience. OK in a "personal" type of site perhaps (your family and friends may let you know about it at the next picnic), but not a good idea for a business site.

  14. #14
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, well thanks for the input!

    i may have found a new solution. possibly. we'll see!

    thanks for the help!


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
  •