Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

LiveValidationPHP

Featured Replies

Hi there,

 

I found this script for validating forms with Javascript and PHP.

 

http://livevalidationphp.leihitu.nl/index.php?page=home

 

It all works perfectly fine, apart from the fact I cannot see where to actually send the information in the form...

 

Here's a basic example of a working form:

 

<?php
	include("livevalidationphp.class.php"); // the LiveValidationPHP scripts
	include("rules.inc.php"); // hold the rules
	
	$html="";			
	$frmTestLive=new LiveValidationMassValidatePHP("frmTestLive",$_POST);
	$frmTestLive->addRules($formRules["frmTestLive"]);						
	$html=$frmTestLive->generateAll();

	// check for a post action
	$frmTestErrors=array();
	if(isSet($_POST["action"]))
	{
		if($_POST["action"]=="send_test_form")
		{
			$frmTestErrors=$frmTestLive->validate();
		}
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<title>LiveValidationPHP | Example 1</title>
		
		<link href="livevalidation/livevalidation.css" rel="stylesheet" type="text/css" media="screen">
		<script language="javascript" type="text/javascript" src="livevalidation/livevalidation.js"></script>
	</head>

	<body>
	
	<h1>Example 1</h1>
	
	<?php
		if(count($frmTestErrors)>0)
		{
			print "<strong>You have errors:</strong>";
			print "<pre>";
			print_r($frmTestErrors);
			print "</pre>";
		}
	?>
	
    <form name='frmTest' id='frmTest' action='' method='post'>
    
        <input type='hidden' name='action' value='send_test_form'>

            <input type='text' name='element_1' id='element_1' value='' placeholder='Name'>

            <input type='text' name='element_2' id='element_2' value='' placeholder='Email'>

            <input type='text' name='element_3' id='element_3' value='' placeholder='Message'>

            <input type='submit' value='go'>
        
    </form>
	
	<script>
	<?php
		print $html;
	?>
	</script>
	
	</body>
</html>

When I've done this before I've always used the action'' part on the form to link to a contact.php or something, but none of the examples are using this, just wondering if anyone knows how to simply send the form once it's valid?

 

The only other relevant file I can think of would be this:

 

http://pastebin.com/raw.php?i=24vA5RZh

 

The others are just one PHP file for the error array messages, and a second for the javascript validation.

It post to page itself.

 

so if POST is isset it will call validate() function

 

 

if(isSet($_POST["action"]))
{
if($_POST["action"]=="send_test_form")
{
$frmTestErrors=$frmTestLive->validate();
}
}

Yup you should check your validate(); function, if you wanna show a message after sending just put make something like this and test it out if you see a message:

if(isSet($_POST["action"]))
    {
        if($_POST["action"]=="send_test_form")
        {
            $frmTestErrors=$frmTestLive->validate();
                   
                 echo $frmTestErrors;
                 echo "Thnx for sending the form!";

        }
    }
  • Author

Cheers guys,

 

 

 

Yup you should check your validate(); function, if you wanna show a message after sending just put make something like this and test it out if you see a message:

if(isSet($_POST["action"]))
    {
        if($_POST["action"]=="send_test_form")
        {
            $frmTestErrors=$frmTestLive->validate();
                   
                 echo $frmTestErrors;
                 echo "Thnx for sending the form!";

        }
    }

 

This works fine, however there seems to be more than one validation function. I actually checked this and couldn't really see where to tell it to send...

		function validate()
		{
			$payload=array();
			$hasErrors=false;
			
			
			
			$count=count($this->rules);
			for($i=0;$i<$count;$i++)
			{
				$currentRule=$this->rules[$i];
				if($resultArray=$currentRule->validate())
				{
					if($resultArray["success"]==false)
					{
						$hasErrors=true;	
						$this->errors[]=$resultArray["payload"];
					}
				}
			}
			
			return $this->errors;

		}
function validate()
		{
			$payload=array();
			$payload["success"]=false;
			
			if($this->method!="")
			{
				$actionFunction=$this->method;
				
				if(method_exists($this,$actionFunction)) 
				{
					if($this->$actionFunction()==false)
					{
						$payload["payload"]="[" . $this->display . "] " . $this->args["failureMessage"];
					} else {
						$payload["success"]=true;
						unset($payload["payload"]);
					}
				}				
				
			}
			
			return $payload;
		}
function validate()
		{
			$errors=array();
			
			$countElements=count($this->fields);
			for($q=0;$q<$countElements;$q++)			
			{
				$currentElement=$this->fields[$q];
				
				$errors=array_merge($currentElement->validate(),$errors);
			}			
			
			return $errors;
			
		}

http://pastebin.com/raw.php?i=24vA5RZh

There's some generate functions at the bottom which look more like that I'm after, but I'm still a bit lost to be fair. Any ideas?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.