[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

PHP Form, validation, thank you page

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
a204801
Asked:
a204801
  • 2
1 Solution
 
pmessanaCommented:
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
 
aconradCommented:
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
 
aconradCommented:
ummm :) add at line 23 :
return false
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now