Return to Snippet

Revision: 34618
at February 26, 2011 19:20 by mikael12


Updated Code
<?php
        $js_back = 'javascript:history.go(-1)';

	if (isset($_POST['send']))
	{
		if ($_POST['captcha'] != 'hello')
			die('<p class="error">Antispam failed. <a href="'.$js_back.'">Try again</p>');
		
		$secured = array();
		$secured = array_map('htmlspecialchars', array_map('strip_tags', $_POST));
		extract($secured);

		$inputs = array('cname' => 'Firstname, surname', 'cemail' => 'Email', 'msg' => 'Message');
		foreach ($inputs as $key => $value)
		{
			if (empty(${$key}))
				die('<p class="error">Input '.$value.' is required. <a href="'.$js_back.'">Try again</a></p>');
		}

		// Code...
	}

?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
	<table>
		<tbody>
			<tr>
				<td><label for="cname">Firstname, surname:</label></td>
				<td><input type="text" name="cname" id="cname" size="40" /></td>
			</tr>
			<tr>
				<td><label for="cemail">E-mail:</label></td>
				<td><input type="text" name="cemail" id="cemail" size="40" /></td>
			</tr>
			<tr>
				<td><label for="msg">Message:</label></td>
				<td><textarea name="msg" rows="8" cols="38" id="msg"></textarea></td>
			</tr>
			<tr>
				<td>Antispam:</td>
				<td><input type="text" name="captcha" /> write in "hello"</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" name="send" value="Send" /></td>
			</tr>
		</tbody>
	</table>
</form>

Revision: 34617
at January 9, 2011 22:11 by mikael12


Updated Code
<?php

	if (isset($_POST['send']))
	{
		if ($_POST['captcha'] != 'hello')
			die('<p class="error">Antispam failed. <a href="javascript:history.go(-1)">Try again</p>');
		
		$secured_post = array();
		$secured_post = array_map('htmlspecialchars', array_map('strip_tags', $_POST));
		extract($secured_post);

		$inputs = array('cname' => 'Firstname, surname', 'cemail' => 'Email', 'msg' => 'Message');
		foreach ($inputs as $key => $value)
		{
			if (empty(${$key}))
				die('<p class="error">Input '.$value.' is required. <a href="javascript:history.go(-1)">Try again</a></p>');
		}

		// Code...
	}

?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
	<table>
		<tbody>
			<tr>
				<td><label for="cname">Firstname, surname:</label></td>
				<td><input type="text" name="cname" id="cname" size="40" /></td>
			</tr>
			<tr>
				<td><label for="cemail">E-mail:</label></td>
				<td><input type="text" name="cemail" id="cemail" size="40" /></td>
			</tr>
			<tr>
				<td><label for="msg">Message:</label></td>
				<td><textarea name="msg" rows="8" cols="38" id="msg"></textarea></td>
			</tr>
			<tr>
				<td>Antispam:</td>
				<td><input type="text" name="captcha" /> write in "hello"</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" name="send" value="Send" /></td>
			</tr>
		</tbody>
	</table>
</form>

Revision: 34616
at November 2, 2010 20:56 by mikael12


Updated Code
<?php

	if (isset($_POST['send']))
	{
		if ($_POST['captcha'] != 'hello')
			die('<p class="error">Antispam failed. <a href="javascript:history.go(-1)">Try again></p>');
		
		$secured_post = array();
		$secured_post = array_map('htmlspecialchars', array_map('strip_tags', $_POST));
		extract($secured_post);

		$inputs = array('cname' => 'Firstname, surname', 'cemail' => 'Email', 'msg' => 'Message');
		foreach ($inputs as $key => $value)
		{
			if (empty(${$key}))
				die('<p class="error">Input '.$value.' is required. <a href="javascript:history.go(-1)">Try again</a></p>');
		}

		// Code...
	}

?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
	<table>
		<tbody>
			<tr>
				<td><label for="cname">Firstname, surname:</label></td>
				<td><input type="text" name="cname" id="cname" size="40" /></td>
			</tr>
			<tr>
				<td><label for="cemail">E-mail:</label></td>
				<td><input type="text" name="cemail" id="cemail" size="40" /></td>
			</tr>
			<tr>
				<td><label for="msg">Message:</label></td>
				<td><textarea name="msg" rows="8" cols="38" id="msg"></textarea></td>
			</tr>
			<tr>
				<td>Antispam:</td>
				<td><input type="text" name="captcha" /> write in "hello"</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" name="send" value="Send" /></td>
			</tr>
		</tbody>
	</table>
</form>

Revision: 34615
at October 26, 2010 03:51 by mikael12


Updated Code
<?php

	if (isset($_POST['send']))
	{
		if ($_POST['captcha'] != 'hello')
			die('<p class="error">Antispam failed. <a href="javascript:history.go(-1)">Try again></p>');
		
		$secured_post = array();
		$secured_post = array('htmlspecialchars', array_map('strip_tags', $_POST));
		extract($secured_post);

		$inputs = array('cname' => 'Firstname, surname', 'cemail' => 'Email', 'msg' => 'Message');
		foreach ($inputs as $key => $value)
		{
			if (empty(${$key}))
				die('<p class="error">Input '.$value.' is required. <a href="javascript:history.go(-1)">Try again</a></p>');
		}

		// Code...
	}

?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
	<table>
		<tbody>
			<tr>
				<td><label for="cname">Firstname, surname:</label></td>
				<td><input type="text" name="cname" id="cname" size="40" /></td>
			</tr>
			<tr>
				<td><label for="cemail">E-mail:</label></td>
				<td><input type="text" name="cemail" id="cemail" size="40" /></td>
			</tr>
			<tr>
				<td><label for="msg">Message:</label></td>
				<td><textarea name="msg" rows="8" cols="38" id="msg"></textarea></td>
			</tr>
			<tr>
				<td>Antispam:</td>
				<td><input type="text" name="captcha" /> write in "hello"</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" name="send" value="Send" /></td>
			</tr>
		</tbody>
	</table>
</form>

Revision: 34614
at October 26, 2010 03:49 by mikael12


Initial Code
<?php

	if (isset($_POST['send']))
	{
		if ($_POST['captcha'] != 'hello')
			die('<p class="error">Antispam failed. <a href="javascript:history.go(-1)">Try again></p>');
		
		$secured_post = array();
		$secured_post = array('htmlspecialchars', array_map('strip_tags', $_POST));
		extract($secured_post);

		$inputs = array('cname' => 'Firstname, surname', 'cemail' => 'Email', 'msg' => 'Message');
		foreach ($inputs as $key => $value)
		{
			if (empty(${$key}))
				die('<p class="error">Input '.$value.' is required. <a href="javascript:history.go(-1)">Try again</a></p>');
		}

		// Code...
	}

?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']; ?>" method="post">
	<table>
		<tbody>
			<tr>
				<td><label for="cname">Firstname, surname:</label></td>
				<td><input type="text" name="cname" id="cname" size="40" /></td>
			</tr>
			<tr>
				<td><label for="cemail">E-mail:</label></td>
				<td><input type="text" name="cemail" id="cemail" size="40" /></td>
			</tr>
			<tr>
				<td><label for="msg">Message:</label></td>
				<td><textarea name="msg" rows="8" cols="38" id="msg"></textarea></td>
			</tr>
			<tr>
				<td>Antispam:</td>
				<td><input type="text" name="captcha" /> write in "hello"</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" name="send" value="Send" /></td>
			</tr>
		</tbody>
	</table>
</form>

Initial URL

                                

Initial Description

                                

Initial Title
Form processing with input checking, simple captcha and error reporting

Initial Tags

                                

Initial Language
PHP