?
Solved

PHP Form, validation, thank you page

Posted on 2009-05-07
3
Medium Priority
?
258 Views
Last Modified: 2012-05-06
Looking for a simple form:

-First Name
-Last Name
-Email

The key is i don't have validation.  I just want basic client side validation.  Make sure first/last is entered and valid email address.

Any help, much appreciated.

<form action="#" method="POST">
<input type=hidden name="retURL" value="http://www.mysite.com/newsletter_signedup.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#CCCCCC"><table width="100%" border="0" cellspacing="1" cellpadding="10">
      <tr>
        <td bgcolor="#FFFFFF"><label for="first_name">First Name</label></td>
        <td bgcolor="#FFFFFF"><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF"><label for="last_name">Last Name</label></td>
        <td bgcolor="#FFFFFF"><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF"><label for="email">Email</label></td>
        <td bgcolor="#FFFFFF"><input  id="email" maxlength="80" name="email" size="20" type="text" /></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF">&nbsp;</td>
        <td bgcolor="#FFFFFF"><input type="submit" name="submit"></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>

Open in new window

0
Comment
Question by:a204801
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:pmessana
ID: 24332545
If you are using Dreamweaver I would recommend using the Adobe Spry framework for validation, very easy and simple to set up.  You don't need to be using Dreamweaver but it helps.  Let me know if you are open to using it and I can get you exact code if you'd like.
0
 
LVL 4

Accepted Solution

by:
aconrad earned 1500 total points
ID: 24332557
client validation = javascript validation i hope :)

<script>
function checkme(){
 
  var err='';
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  
  
  if (!(filter.test(document.forms['asd'].elements['email'].value))) {
  	err += ' - invalid email address\n';
  }	
  
  if (document.forms['asd'].elements['first_name'].value=='') {
  	err += ' - blank first name\n';
  }
  
  if (document.forms['asd'].elements['last_name'].value=='') {
  	err += ' - blank last name\n';
  }
  
  if (err=='') return true;
  
  alert('Please correct these errors\n'+err);
  
  
}
 
function checkemail(str){
 
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	testresults=true
	else{
 
		testresults=false
	}
	return (testresults)
}
 
</script>
 
<form action="#" method="POST" name="asd" onsubmit="return checkme();">
<input type=hidden name="retURL" value="http://www.mysite.com/newsletter_signedup.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#CCCCCC"><table width="100%" border="0" cellspacing="1" cellpadding="10">
      <tr>
        <td bgcolor="#FFFFFF"><label for="first_name">First Name</label></td>
        <td bgcolor="#FFFFFF"><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF"><label for="last_name">Last Name</label></td>
        <td bgcolor="#FFFFFF"><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF"><label for="email">Email</label></td>
        <td bgcolor="#FFFFFF"><input  id="email" maxlength="80" name="email" size="20" type="text" /></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF"> </td>
        <td bgcolor="#FFFFFF"><input type="submit" name="submit"></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>

Open in new window

0
 
LVL 4

Expert Comment

by:aconrad
ID: 24332559
ummm :) add at line 23 :
return false
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question