• 0

finishing up a contact form need help


Question

Hello everyone,

I have a form set up from dreamweaver cs5, but I was wondering what I need to do to actually get it to work?

My code for the form looks like this.

  <form action="" method="post" enctype="text/plain" class="subscription_box" onsubmit="MM_validateForm('subscription_email','','NisEmail');return document.MM_returnValue">
  <label for="subscription_email"></label>
  <input name="subscription_email" type="text" id="subscription_email" value="insert email, then press enter." size="40" maxlength="64" onfocus="if(this.value=='insert email, then press enter.'){this.value='';}" onblur="if(this.value==''){this.value='insert email, then press enter.';}"/>
  </form>

Also, I have set some validation for my form where the user has to input an email address. This was from dreamweaver cs5. If the user does not input an email address, there's a pop up error message that says that the user needs to have a email address. This is kind of ugly, I was wondering how I can get a nicer validation to my form? Maybe an X or a check mark. Just something nicer than a popup error.

My code for the validation from dreamweaver is this:

<script type="text/javascript">
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
</script>

Thank you

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

First off, you do not run a website out of Dreamweaver itself. You will need to put this in a more appropriate testing environment. Whether you upload this to your hosting account or you can setup WAMP, XAMPP.. Or whatever you'd prefer. Dreamweaver should be used for developing your website--not testing it.

Next, you need an actual "backend" to your form. You can't just toss up some inputs and textareas and expect it to work. Where you see form, you require an action or the file that contains all of the code for submitting the form.

Several threads have been posted on forms and each time I've suggested the following: PHP Mail Form by a good friend of mine, Jem.

As far as form validation goes, you can check out A jQuery inline form validation, because validation is a mess. Will give you just what you need.

Link to comment
Share on other sites

  • 0

Quick question. I'm trying to understand the coding from the PHP mail form, but they are all in another page. If I have a page already set up and I want a form to be implemented in that page, do I just copy the necessary code into it, say my index.php? Or do I need to set up another page (mail form page) and then do some code from my index.php to call to that page (mail form page)?

thanks

Link to comment
Share on other sites

  • 0

I might be doing this wrong. I'm trying to set up a Newsletter subscription. Do I follow the same steps? I would like the emails to be sent somewhere easily accessible instead of sending it to my email everytime someone subscribes.

Thank you

Link to comment
Share on other sites

  • 0

Quick question. I'm trying to understand the coding from the PHP mail form, but they are all in another page. If I have a page already set up and I want a form to be implemented in that page, do I just copy the necessary code into it, say my index.php? Or do I need to set up another page (mail form page) and then do some code from my index.php to call to that page (mail form page)?

thanks

If you want the form to be in the same file (index.php), your form tag would look something like this:

<form action="index.php" method="post" enctype="text/plain" class="subscription_box" onsubmit="MM_validateForm('subscription_email','','NisEmail');return document.MM_returnValue">

Or you could do it the long way and state it (the form action) with PHP:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="text/plain" class="subscription_box" onsubmit="MM_validateForm('subscription_email','','NisEmail');return document.MM_returnValue">

So, to recap, your index.php file would look sort of like this:

<html>
<head>
<title>Contact Form</title>
</head>
<body>
<?php
{Insert PHP contact form code here}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="text/plain" class="subscription_box" onsubmit="MM_validateForm('subscription_email','','NisEmail');return document.MM_returnValue">
{Insert the rest of the form here}
</body>
</html>

Obviously, you would want this to validate, so, specify a doctype, charset, etc...

Link to comment
Share on other sites

  • 0

Asparagus, if you reference my post and the script in question: The form script and inputs are on the same page. The entire form is already setup for him to literally copy/paste and change his email details and go.

As far as wanting it to be a newsletter, you didn't mention that from the getgo. If you do not know how to setup a newsletter script, then you'll need to look around tutorials if you want to learn how to set it up yourself or to just grab something premade.

Options for newsletters:

http://net.tutsplus.com/freebies/others/fantastic-ajax-newsletter-module/

http://net.tutsplus.com/articles/news/build-a-newsletter-system-with-php-and-mysql-new-plus-tut/

http://net.tutsplus.com/tutorials/wordpress/build-a-wordburner-email-newsletter-manager-using-wordpress-and-feedburner/

Link to comment
Share on other sites

  • 0

Asparagus, if you reference my post and the script in question: The form script and inputs are on the same page. The entire form is already setup for him to literally copy/paste and change his email details and go.

Don't worry, I was aware of that. :)

I was merely giving him generic instructions were he to use a script that's just that - a script.

Link to comment
Share on other sites

  • 0

Sorry guys! I need more help :(

I tried to build a newsletter with this module: http://net.tutsplus.com/freebies/others/fantastic-ajax-newsletter-module/

I downloaded the file and I get a index.php and other files. Its a module, but how do I set it up with my page? Do I set the form action="index.php"? Does that mean, I can change the name to newsletter.php too and have my main page index.php?

Also, how would I gain access to the module? Is it just mysite.com/newsletter.php? Thanks

I'm sorry, but I'm a real n00b. :blush:

Link to comment
Share on other sites

  • 0

The filename is anything you name it to if you do not want index.php. Alternatively, you can set it up as domain.com/newsletter/ and just retain all newsletter stuff in its own directory.. And if you need the form info used elsewhere, just ensure that the action is set to <directory>/filename.php.

Edit: Looking at that AJAX Newsletter Module I'm regretting even recommending it to you. It's not the best in terms of security (eg: if you don't set anything up to prevent public access, anyone can scrape for those emails..)

Some others:

http://codecanyon.net/item/newsletter-system/52667 / Paid

Link to comment
Share on other sites

  • 0

I was looking into the module, and theres a place where I can set my password. I'm not sure I can afford anything right now. Hopefully I can figure this out.

Thanks!

Link to comment
Share on other sites

  • 0

So I encountered a problem. I tried to set the module newsletter in form action=" " but when i tried to enter my email into the form, my page gets sent to the module page. What am I supposed to set my action and how will that email be stored into the module?

Maybe I should just purchase that newsletter. is it monthly fee or just one time fee?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.