# Need some help ....how to validate this form

**URL:** <https://forum.kirupa.com/t/need-some-help-how-to-validate-this-form/163530>\
**Category:** Uncategorized\
**Created:** [September 23, 2005, 3:03am UTC](https://forum.kirupa.com/t/need-some-help-how-to-validate-this-form/163530 "2005-09-23T03:03:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![multimediamkt](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@multimediamkt](https://forum.kirupa.com/u/multimediamkt)\
**Post date:** [September 23, 2005, 3:03am UTC](https://forum.kirupa.com/t/need-some-help-how-to-validate-this-form/163530/1 "2005-09-23T03:03:54Z")

</div>

sept 23 2005

The pasted bellow code is a simple order form which I intend to validate ;  
There will be lots of checkbox (script would have to be lithe to comply with a variable number of checkbox );  
, 8 x input texts (one of which an email field to be validated on email format ) and 1 x select name ;

Perhaps a javascript would be a simpler solution , but I´ve encountered the following difficulty :

- name of the checkbox inputs are the same for all : name=“check” - it makes impossible to identify every checkbox  
on javascript ;
- I think it´s got to be changed including the way these lines are written :

> foreach( (array)$\_POST[‘check’] as $value){  
> $check\_msg .= "Checked: $value  
> ";

Any help would be welcome  
Cheers

PS - despite this is not a javascript forum I will ask if someone knows where can I find  
tutorials on how to validate forms (I´ve found several scripts that have not fit what I need)

> 

… Order Form… :

\<form name=“form1” method=“post” action=“formpedido1.php”\>  
\<br\>  
\<input type=“text” name=“hpxxxxxxabc” size=“2” maxlength=“2”\>  
\<br\>

\<input type=“checkbox” name=“check” value=“hpxxxxxxabc\_clicado”\>  
\<br\>  
\<input type=“text” name=“eps00001a” size=“2” maxlength=“2”\>  
\<br\>  
\<input type=“checkbox” name=“check” value=“eps00001a\_clicado”\>

\<br\>  
\<input type=“text” name=“nome” maxlength=“50” size=“45” style class=“formbg”\>  
\<br\>  
\<input type=“text” name=“endereco” maxlength=“50” size=“40” style class=“formbg”\>  
\<br\>  
\<input name=“numero” type=“text” class=“formbg” id=“numero” style size=“6” maxlength=“6”\>  
\<br\>  
\<input name=“cidade” type=“text” class=“formbg” id=“cidade” style size=“35” maxlength=“35”\>  
\<br\>  
\<select name=“estado” size=“1” style class=“formbg”\>  
\<option value=“value”\>( Selecione )\</option\>  
\<option selected\>A\</option\>  
\<option\>B\</option\>  
\<option\>C\</option\>  
\<option\>etc\</option\>  
\</select\>  
\<br\>  
\<input name=“cep” type=“text” id=“cep” size=“8” maxlength=“8”\>  
\<br\>  
\<input type=“text” name=“codigo\_area” size=“15” maxlength=“5” style class=“formbg”\>  
\<br\>  
\<input type=“text” name=“telefone” size=“15” maxlength=“15” style class=“formbg”\>  
\<br\>  
\<input type=“text” name=“email” size=“35” maxlength=“100” style class=“formbg”\>  
\<br\>  
\<textarea name=“comentarios” cols=“70” rows=“5”\> \</textarea\>  
\<br\>

\<input type=“submit” name=“Submit” value=“Confirmar pedido” style=“background-color: #ffcc00” \>  
\<br\>

\<input type=“reset” name=“Submit2” value=“Limpar” style=“background-color: #ffcc00”\>

… FILE formpedido1.php … :

\<?php  
if(isset($\_POST[‘Submit’])) {

$to = “john\_doe@nowhere.helpme”;  
$subject = “formulario\_de\_pedido\_01”;   
$nome = $\_POST[‘nome’];  
$endereco = $\_POST[‘endereco’];  
$numero = $\_POST[‘numero’];  
$cidade = $\_POST[‘cidade’];  
$estado = $\_POST[‘estado’];  
$cep = $\_POST[‘cep’];  
$codigo\_area = $\_POST[‘codigo\_area’];  
$telefone = $\_POST[‘telefone’];  
$email = $\_POST[‘email’];  
$comentarios = $\_POST[‘comentarios’];  
$hpxxxxxxabc = $\_POST[‘hpxxxxxxabc’];  
$eps00001a = $\_POST[‘eps00001a’];

// … how to change the lines bellow ???  
foreach( (array)$\_POST[‘check’] as $value){  
$check\_msg .= "Checked: $value  
";  
}

// \_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_ \_\_\_\_\_

```
                                     $body = "Nome: $nome

                                                   Endereco: $endereco

		 Numero : $numero

		 Cidade : $cidade

		 Estado: $estado

		 Cep: $cep

		 Cod. Area: $codigo_area

		 Fone: $telefone

		 Email: $email

		 Comentarios: $comentarios
		 
		 Items pedidos: 

		 $check_msg

		 Quantidade de hpxxxxxxabc : $hpxxxxxxabc

		 Quantidade de eps00001a : $eps00001a
	 
		 ";

```

// \_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_\_

```
header("Location: order_confirmation.htm");
mail($to, $subject, $body);

```

} else {  
echo “error\_invalid\_function”;  
}  
?\>
