We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18666
    • 8 Posts
    Hi,

    Just wondering if it’s my installation only or it’s the source. I can’t seem to get the contact form to submit. When I press submit, it just reloads the page as if it has just been called the first time and displays the form.

    See it at http://www.livingspringsministries.org.uk/contact.html

    the content of this page
    [[ContactForm? &sendTo=`[email protected]`]]


    my ContactForm snippet:

    <?php
    // Email / Contact Form
    // Simple XHTML validating email form, that sends different subjects and messages. 
    // people in a company.
    //
    // Version 1.0
    // September 9, 2005
    // [email protected]
    //
    
    // DO NOT ALTER THE FOLLOWING TWO LINES
    $subject_array = array();
    $recipient_array = array();
    
    ///////////////////////////////////
    //  <-----  BEGIN CONFIG  ----->
    ///////////////////////////////////
    // Edit only what's between the quotation marks in the lines below.
    // These will be the subjects that your users can choose from popup
    // lists. You can have as many as you want. Each one must be set up like so:
    // $subject_array[] = "What You Want This Choice To Be";
    // Make sure to remove empty ones that you aren't using. Just delete the entire line.
    
    // Generic email to use for all parts. You can edit
    // the individual instances for more control.
    // Defaults to the built-in email notification account which is set in the System Configuration.
    // Can be set by using as follows:
    // [[ContactForm? &sendTo=`[email protected]`]]
    $email = (isset($sendTo))? $sendTo : '[(emailsender)]';
    
    
    // enter "static" in order to use the static subject line
    $subject_type = "";
    $static_subject = "[Web Inquiry] ".$modx->config['site_url'];
    
    // Otherwise use an array of possible subjects
    $subject_array[] = "Living Springs Ministries General";
    $subject_array[] = "Living Springs Church Related";
    $subject_array[] = "Building Relationships Related";
    $subject_array[] = "Youth Development Related";
    $subject_array[] = "Life Lines Related";
    $subject_array[] = "Growing People Related";
    
    // Recipient ... add or remove lines as needed
    // Format (as few or as many as desired): 
    // $recipient_array["Your Text Here"] = '[email protected]';
    $recipient_array["Living Springs Ministries General"] = "$email";
    $recipient_array["Living Springs Church Related"] = "$email";
    $recipient_array["Building Relationships Related"] = "$email";
    $recipient_array["Youth Development Related"] = "$email";
    $recipient_array["Life Lines Related"] = "$email";
    $recipient_array["Growing People Related"] = "$email";
    //$recipient_array["Press or Interview Request"] = "$email";
    //$recipient_array["Partnering Opportunities"] = "$email";
    
    // enter "static" in order to use the solo recipient
    $recipient_type = "static";
    $static_recipient = "$email";
    
    // Instructions 
    $instructions = "Please select the type of message you'd like to send so we can route it properly. All fields are required.";
    
    // Success Message
    $success = "Thanks for contacting [(site_url)]. Someone will get back to you soon. You may submit another message in the form below.";
    
    // Class for containing Success Message <p>
    $successClass = "message";
    
    // Failure <p> class
    $failClass = "error";
    
    // Empy Field failure message
    $emptyFields = "One of the fields was left blank. Please put something in all fields.";
    
    // General failure message
    $generalFail = "Sorry, there was an error! Please try again later.";
    
    // Bad email failure message
    $failedEmail= (isset($_POST['email']))? $_POST['email']: '';
    $emailFail = "The email address you supplied ({}) does not appear to be valid. Please try again.";
    
    // Debug mode for testing
    $debug = false;
    
    //  <-----  END CONFIG  ----->
    ///////////////////////////////////
    $SendMail = '';
    if ($debug && $_POST) {
    	$SendMail .= "POST variables from Document ID [*id*]:\n";
    	foreach ($_POST as $key => $value) {
    		$SendMail .= "\t$key => $value\n";
    	}
    }
    
    $from= '';
    $from_email= '';
    $message= '';
    
    $postSend= isset($_POST['send'])? $_POST['send']: 'false';
    if ($postSend == 'true') { 
        $to = ($recipient_type=="static") ? $static_recipient : $_POST['to'];
        $from = $_POST['name'];
        $from_email = $_POST['email'];
        $the_subject = ($subject_type=="static") ? "$static_subject" : $_POST['subject'];
        $message = $_POST['message'];
        if ( ($from == '')||($from_email == '')||($message == '') ) {
            $SendMail .= "<p class=\"$failClass\">$emptyFields</p>";
        } elseif (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $from_email)) {
            $subject = $the_subject;
            $headers = "From: $from <$from_email>\r\n";
            
            // clean out potential tomfoolery...
            $message = $modx->stripTags($message);
            
            $body = "Name: $from\nEmail: $from_email\nMessage:\n\n" . $message;
            if (mail($to, $subject, $body, $headers)) {
                $SendMail .= "<p class=\"$successClass\">$success</p>";
                $SendMail .= ($debug) ? "<p>$to\n$headers\n$subject\n$body</p>" : '';
                $from="";
                $from_email="";
                $message="";
            } else {
                $SendMail .= "<p class='$failClass'>$generalFail</p>";
                $send = "false";
            }
        } else {
            $SendMail .= "<p class=\"$failClass\">$emailFail</p>";
            $send = "false";
        } 
    } else {
        $SendMail .= "<p>$instructions</p>";
    }
    $SendMail .=<<<EOD
    <div class="emailform">
    
    
    
        <form method="post" name="EmailForm" id="EmailForm" action="[~[*id*]~]" >
            <fieldset>
                <h3>[(sitename)] Contact Form</h3>
    						<table cellspacing="0" cellpadding="5" border="0" style="margin: auto; width: 60%">
    							<tr>
    								<td>
    									<input type="hidden" name="send" value="true" />
    									<label for="name">Your Name: </label>
    								</td>
    								<td align="right">
    									<input type="text" name="name" id="name" size="30" value="$from" />
    								</td>
    							</tr>
    							<tr>
    								<td>
    									<label for="email">Your Email Address: </label>
    								</td>
    								<td align="right">
    									<input type="text" name="email" id="email" size="30" value="$from_email" />
    								</td>
    							</tr>
    							<tr>
    								<td>
    									<label for="to">Regarding:</label> 
    								</td>
    								<td align="right">
    									<select name="to" id="to">
    EOD;
    
            foreach ($recipient_array as $key=>$value) {
                $SendMail .= "<option value=\"{$value}\">{$key}</option>\n";
            }
    
    $SendMail .=<<<EOD
                			</select>
    								</td>
    							</tr>
    							<tr>
    								<td colspan="2">
    									<label for="message">Message:</label>
    								</td>
    							</tr>
    							<tr>
    								<td colspan="2" align="right">
    									<textarea cols="50" rows="10" name="message" id="message">$message</textarea><br />
    									<label> </label><input type="submit" value="Send this Message" class="button" />
    								</td>
    							</tr>
    						</table>
            </fieldset>
        </form>
    </div>
    EOD;
    
    return $SendMail;
    ?>
    • You are calling it on a cached page, using a cached call. Try calling via
      [!ContactForm? &sendTo=`[email protected]`!]
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 22815
        • 1,097 Posts
        Incidentally, there is no distinct PHP bbcode tag on this forum - you need to use CODE but have the <?php comments. I’ve taken the liberty of amending your post accordingly.
          No, I don&#39;t know what OpenGeek&#39;s saying half the time either.
          MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
          Forum: Where to post threads about add-ons | Forum Rules
          Like MODx? donate (and/or share your resources)
          Like me? See my Amazon wishlist
          MODx "Most Promising CMS" - so appropriate!