Adding fields to Slick Ajax Contact Form?

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

06-Jul-11 16:00
Just to remind everyone, I am a print designer, not a web designer......so the problem is obvious......just not to me.

Here is a page with the code.
The page is otherwise empty, because I don't want to use to contact if it wont work.

http://www.agraphics.biz/jquerycontact

Basically I just wanted to add space for a phone number and a drop-down selection box but it wont post either field.

And now I get a success message, but there is no email that comes through.
12-Jul-11 02:04
@10000nails: What do you mean by "it won't post either field"? What PHP error message are you getting (if any)?

Your markup looks OK.

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
12-Jul-11 08:24
Whatever is entered in those fields wont come through in an email. It will post the senderName, senderEmail, and message but that's all.
13-Jul-11 04:41
@10000nails: You have an error in your PHP code:


$senderPhone = isset( $_POST['senderPhone'] ) ? preg_replace( "/[^\.\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : "";


Should be:


$senderPhone = isset( $_POST['senderPhone'] ) ? preg_replace( "/[^\.\' a-zA-Z0-9]/", "", $_POST['senderPhone'] ) : "";


--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
14-Jul-11 04:48
I also added a field to Slick Ajax Contact Form and changed processForm.php as follow:


// Read the form values
$success = false;
$senderName = isset( $_POST['senderName'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : "";
$senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
$newsletter = isset( $_POST['newsletter'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['newsletter'] ) : "";

// If all values exist, send the email
if ( $senderName && $senderEmail && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . " <" . $senderEmail . ">";
$success = mail( $recipient, EMAIL_SUBJECT, $message, $newsletter, $headers );
}


The e-mail is successfully sent but the information about the recipient is not passing. What I receive is an anonymous email.

Any help is appreciated...
18-Jul-11 23:40
@perfisa: What do you mean by "the information about the recipient"? The recipient's real name?

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
08-Aug-11 11:08
I believe that I am having a similar issue. I am trying to add more fields but I cannot seem to do it quite right. I am trying to add 4 more fields (one for Address, City, State and Zip).

Here is the modified form processor:


<?php

// Define some constants
define( "RECIPIENT_NAME", "John Doe" );
define( "RECIPIENT_EMAIL", "johndoe@johndoe.com" );
define( "EMAIL_SUBJECT", "Visitor Message" );

// Read the form values
$success = false;
$senderName = isset( $_POST['senderName'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : "";
$senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : "";

$senderAddress = isset( $_POST['senderAddress'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderAddress'] ) : "";
$senderCity = isset( $_POST['senderCity'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderCity'] ) : "";
$senderState = isset( $_POST['senderState'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderState'] ) : "";
$senderZip = isset( $_POST['senderZip'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderZip'] ) : "";

$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";


// If all values exist, send the email
if ( $senderName && $senderEmail && $senderAddress && $senderCity && $senderState && $senderZip && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . " <" . $senderEmail . ">";
$success = mail( EMAIL_SUBJECT, $recipient, $senderEmail, $senderAddress, $senderCity, $senderState, $senderZip, $message, $headers );
}

// Return an appropriate response to the browser
if ( isset($_GET["ajax"]) ) {
echo $success ? "success" : "error";
} else {
?>
<html>
<head>
<title>Thanks!</title>
</head>
<body>
<?php if ( $success ) echo "<p>Thanks for sending your message! We'll get back to you shortly.</p>" ?>
<?php if ( !$success ) echo "<p>There was a problem sending your message. Please try again.</p>" ?>
<p>Click your browser's Back button to return to the page.</p>
</body>
</html>
<?php
}
?>


And for the form:



<form id="contactForm" action="index_new_email1_process_form.php" method="post">

<h2>Send us an email...</h2>

<ul>

<li>
<label for="senderName">Name <span class="req">*</span></label>
<input type="text" name="senderName" id="senderName" placeholder="Please type your name" required="required" maxlength="40" />
</li>

<li>
<label for="senderEmail">Email Address <span class="req">*</span></label>
<input type="email" name="senderEmail" id="senderEmail" placeholder="Please type your email address" required="required" maxlength="50" />
</li>

<li>
<label for="senderAddress">Address</label>
<input type="text" name="senderAddress" id="senderAddress" placeholder="Please type your address" maxlength="50" />
</li>

<li>
<label for="senderCity">City</label>
<input type="text" name="senderCity" id="senderCity" placeholder="Please type your City" maxlength="50" />
</li>

<li>
<label for="senderState">State</label>
<input type="text" name="senderState" id="senderState" placeholder="Please type your State" maxlength="50" />
</li>

<li>
<label for="senderZip">Zip</label>
<input type="text" name="senderZip" id="senderZip" placeholder="Please type your Zip" maxlength="50" />
</li>

<li>
<label for="message" style="padding-top: .5em;">Message <span class="req">*</span></label>
<textarea name="message" id="message" placeholder="Please type your message" required="required" cols="80" rows="10" maxlength="10000"></textarea>
</li>
<li>
Items marked <span class="req">*</span> are required.
</li>

</ul>

<div id="formButtons">
<input type="submit" id="sendMessage" name="sendMessage" value="Send Email" />
<input type="button" id="cancel" name="cancel" value="Cancel" />
</div>

</form>



It was working just fine before I attempted to add those new fields. Now it will only display the There was a problem sending your message. Please try again message.

Thanks in advance for your help!

[Edited by modad on 08-Aug-11 11:11]
09-Aug-11 05:31
@modad: You're passing invalid arguments to the PHP mail() function ($senderAddress, $senderCity etc). Here are the parameters that mail() supports:

http://php.net/manual/en/function.mail.php

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
20-Mar-12 09:02
I'm having the same problem as Modad, I followed the link you've posted but I can't make sense of what exactly I should be looking at?
25-Sep-12 12:51
Hi, I'm having the exact same issue. I wasn't aware only certain parameters were supported in the form.

So.. are there other ways to add new fields to the form? I.e. like in the above example, if we would like to add the field 'senderZip', and this code would be invalid:


$senderZip = isset( $_POST['senderZip'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderZip'] ) : "";


What would be the correct way to add new fields? I'm guessing it would involve additional code in the form itself (like a query?), the js file, and the processForm.php?

I would love to learn how to do this!

My purpose would be to be able to add a pre-filled textfield to my form. So I can keep track which page the form is sent from.

--
---

 
New posts
Old posts

Follow Elated