Forum Moderators: open

Message Too Old, No Replies

eMail form help

rookie novice needs help with email form using JS and AJAX

         

rimfirelive

9:43 pm on Sep 28, 2009 (gmt 0)

10+ Year Member



I am hoping someone can help me understand how to finish the code and supporting files for being able to have a simple form, that forwards a "send to a friend" link to my site via email, a confirmation page, and possibly posting the data to a data base. The form that I have so far is located at <snipped url> , and the link is at the bottom. My JS scripts so far are located in "/JS"

I am just a novice and really could use some friendly help :)

Thanks in advance...
G

[edited by: whoisgregg at 2:46 am (utc) on Sep. 30, 2009]
[edit reason] Whoops, no URLs please. See TOS [webmasterworld.com] :) [/edit]

whoisgregg

2:48 am on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, rimfirelive!

If you could post some short code snippets and a description of "what isn't working" then I know you'll find an abundance of friendly help. :)

rimfirelive

3:21 pm on Sep 30, 2009 (gmt 0)

10+ Year Member



Thank you for your advice. I am sure that I am way over my head at this point. Ok... the MTAF "Mail To A Friend" section of my index page has the following code:

<div id="mtaf-container">
<div id="mtaf-title">Send To A Friend:</div>
<form id="mtaf-form">
<p>
<label id="mtaf-box-from-label" for="mtaf-box-from">Your email goes here.</label>
<input id="mtaf-box-from" def="1" type="text" size="10" name="sendfrom" class="required email" />
</p>
<p>
<label id="mtaf-box-label" for="mtaf-box">Your friend's email goes here.</label>
<input id="mtaf-box" def="1" type="text" size="10" name="sendto" class="required email" />
</p>
<p>
<input id="mtaf-send" type="submit" value="Send" />
<input id="mtaf-cancel" type="button" value="Cancel" />
</p>
</form>
<div id="mtaf-errors"></div>
</div>

<script type="text/javascript" src="/js/thickbox.js"></script>
<link rel="stylesheet" type="text/css" href="/css/thickbox_mtaf.css" />
<script type="text/javascript" src="/js/jquery.infieldlabel.min.js"></script>
<script type="text/javascript">
$(document).ready(setup_mtaf);
</script>

<script type="text/javascript">
$(document).ready(function() {
recapture();
});
</script>




<script type="text/javascript">
$(document).ready(
function () {
pingcount=0;
pingTime = new Date();
window.setInterval("keepMeAliveLanding()", 60000);
}
);
</script>

I believe the cooresponding JS is in a file called "flare.js" and the section for MTAF is:

function sendToFriend() {
sendFrom = $('#mtaf-box-from').val();
sendTo = $("#mtaf-box").val();
if(!validateEmail(sendFrom) ¦¦ !validateEmail(sendTo)) {
$('#mtaf-errors').html('Please complete the form before sending.');
return false;
}
$('#mtaf-cancel').hide();
$('#mtaf-send').val('Sending...').attr('disabled','true');
$.ajax(
{
type: "POST",
url: "ajax-email/",
data: "sendto=" + sendTo + "&sendfrom=" + sendFrom,
success: function () {
hide_mtaf();
$("#mtaf").html("&bull;&nbsp;&nbsp;Message sent to " + sendTo);
$("#mtaf").css("font-style","italic");
}
}
);
return false;
}

function setup_mtaf() {
$("#mtaf-form label").inFieldLabels();
$("#mtaf-form").submit(sendToFriend);
$("#mtaf-cancel").click(hide_mtaf);
$("#mtaf-box, #mtaf-box-from").focus(function() {
if ($(this).attr("def") == "1") {
$(this).val("");
$(this).attr("def","0");
}
$('#mtaf-errors').html('');
});
$("#mtaf-form").validate();
}

function show_mtaf() {
tb_show('', '#TB_inline?height=220&width=450&inlineId=mtaf-container&modal=true', null);
return false;
}

function hide_mtaf() {
$('#TB_ajaxContent form')[0].reset();
$('#mtaf-box-from, #mtaf-box').blur();
$('#mtaf-form label.error').hide();
tb_remove();
return false;
}

This is all I that I have so far... My objective is to have the "send" initate an email sent with a link back to my site, and a breif description of the product; and if possible, a DB (SQL) record of those forwards. I am hosted on a Windows server with godaddy. Thanks again to anyone who has the patience to help me :)

lexipixel

12:27 am on Oct 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



being able to have a simple form

That code is NOT simple. You are dealing with jQuery more than "javascript" and appears to be a custom version of the jQuery library:

<script type="text/javascript" src="/js/jquery.infieldlabel.min.js"></script>

(which I beleive is for the "in field label" jQuery form add-on from: [fuelyourcoding.com...] -- that code makes your form labels appear within their respective data input field, again NOT "simple" and really just a toy unless you have a specific need). Anyway, it isn't standard issue jQuery code and adds another layer of complexity to your page.

I suggest getting a standard install of jQuery and eliminating the "extras" and getting the basic Ajax function to work.

Big Suggestion! --- use the FireFox browser and install the Firebug add-on, that will let you debug your code.

It would be a shame if a closing bracket, semi-colon or other common error is the problem and you are pulling out hair looking for something more complicated.

Just guessing but:

$(document).ready(setup_mtaf);

doesn't look right, and seems to be what initializes or "sets up" the rest of it. Maybe it should be:

$(document).ready( function() { setup_mtaf(); });

Also, you have multiple "document ready (functions)" in script tags -- you really only need one (in the <head> section of your page), and can list the various function in proper sequence within that construct:

<script type="text/javascript">
$(document).ready(
//
// jQuery calls here
//
);
</script>

..anyway, look into jQuery, "infield" and use Firebug -- that will give you a lot of insight into what's happening.

rimfirelive

3:17 pm on Oct 1, 2009 (gmt 0)

10+ Year Member



Thank you so much for your valuable time and suggestions. It is quite evident that I have gotten in way over my head at my current skill level... by trying to incorporate code snipetts to get the look and feel that I wanted. As of now, having tried to reserach my madness of reverse engineering this coding with AJAX, JS, and such, that I am also missing a major component of a PHP file handler, or the like, to pass along the posting of information. Honestly, I am at a point that I can't even decifer where to place the PHP handler, and even how to get it (code it) to then mail and post data as needed. Any suggestions of a possible contact for consultation to guide me through, in real time, the basics of how to code the PHP, envoke my mail server at GoDaddy, and then where to even place the file itself? Once that is done, I then have to take on the challange of taking the Order Form that is also part of the index page, and then seamlessly tying it in with the Google check out back-end. Again, I am sure that everyone is saying, "wow, this guy has definately bitten off more than he can chew!" I agree :( Any guidance in direction would be greatly appreciated... once again!
Thanks, G