Sessions?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Good morning list,    

 I have my form up and running but something is missing: if you omit
 required fields, the form returns an error like:
 please fill in ...
 please fill in...

 the error message is displayed above the form on the same page. The
 problem is that upon showing the error message, the fields already
 filled out, return blank so that the user has to fill everything in
 again.

 What i would like to have is that the data already filled out, is
 being saved when the error message kicks in so that the user doesn't
 have to start al over again.

 Am i right in assuming this is done with a session, and if so how
 would i do that?

 here's my script:

$contact_form_action = $_SERVER['PHP_SELF'];
if ((isset($_POST["sendcontact"])) && ($_POST["sendcontact"] == "contactsent")) {
        $contacter_form_error = array();
        if (empty($_POST['empresa_name'])){
                $contacter_form_error[] = 'favor preencher nome da empresa';
        }
        if (empty($_POST['contato_name'])){
                $contacter_form_error[] = 'favor preencher nome do contato';
        }
        if (empty($_POST['fone'])){
                $contacter_form_error[] = 'favor preencher número do telefone';
        }
        if (empty($_POST['contato_email'])){
                $contacter_form_error[] = 'favor preencher seu e-mail';
        }
        if (empty($_POST['produto'])){
                $contacter_form_error[] = 'favor preencher o produto';
        }
        if (empty($_POST['origem'])){
                $contacter_form_error[] = 'favor preencher origem';
        }
        if (empty($_POST['destino'])){
                $contacter_form_error[] = 'favor preencher destino';
        }
        if (empty($_POST['quantidade'])){
                $contacter_form_error[] = 'favor preencher quantidade';
        }
        if (empty($_POST['peso'])){
                $contacter_form_error[] = 'favor preencher peso';
        }
        if (empty($_POST['comprimento'])){
                $contacter_form_error[] = 'favor preencher comprimento';
        }
        if (empty($_POST['altura'])){
                $contacter_form_error[] = 'favor preencher altura';
        }
        if (empty($_POST['largura'])){
                $contacter_form_error[] = 'favor preencher largura';
        }
        else {
                $empresa_name = stripslashes($_POST['empresa_name']);
                $contato_email = stripslashes($_POST['contato_email']);
                
    $body =<<<EOB
 Prezado,
 Favor cotar, conforme os seguintes dados: 

Empresa: $_POST[empresa_name]
Contato: $_POST[contato_name]
Fone: $_POST[fone]
Fax: $_POST[fax]
Email: $_POST[contato_email]
Produto: $_POST[produto]
Origem: $_POST[origem]
Destino: $_POST[destino]
Quantidade: $_POST[quantidade]
Peso: $_POST[peso]
Comprimento: $_POST[comprimento]
Altura: $_POST[altura]
Largura: $_POST[largura]

Grato.
   
Atenciosamente,

$_POST[contato_name]
EOB;
$contato_name = $_POST['contato_name'];
$subjectline = "$websitetitle | Orçamento de empresa";
$notification_message = "Obrigado por nos contatar, $contato_name. Recebemos sua mensagem e entraremos em contato em breve.";
$notification_subject = "Obrigado por sua mensagem para $websitetitle.";
                        
@mail($contato_email,$subjectline,$body, "From: $contato_email"); 
@mail($contato_email,$notification_subject,$notification_message, "From: $youremail");                                          
        
header("Location:$thankyoupage");               
        }
}

==== Some html text ========
?>
// Print form field errors if present
if (count($contacter_form_error)>0){
        print '<p id="bottom"><strong>Algo está errado:</strong></p>'."\n";
        print '<ul>'."\n";
        foreach($contacter_form_error as $form_err) {
                print "<li class=\"error\">$form_err</li>\n";
        }
        print '</ul>'."\n";
}
?> 
<form method="post" id="contactform" action="<? print $contact_form_action; ?>">
<p>Todos os campos obrigatórios são marcados com asteriscos (<span class="required">*</span>).</p>
<fieldset>
<legend>Seus Dados</legend>
<label for="empresa_name">Empresa <span class="required">*</span></label>
<br />
<input type="text" id="empresa_name" name="empresa_name" size="30" value="<? print $empresa_name; ?>" />
<br />
<label for="contato_name">Contato <span class="required">*</span></label>
<br />
<input type="text" id="contato_name" name="contato_name" size="30" value="<? print $contato_name; ?>" />
<br />
<label for="fone">Número do telefone <span class="required">*</span></label>
<br />
<input type="text" id="fone" name="fone" size="30" value="<? print $fone; ?>" />
<br />
<label for="fax">Fax</label>
<br />
<input type="text" id="fax" name="fax" size="30" value="<? print $fax; ?>" />
<br />
<label for="contato_email">E-mail <span class="required">*</span></label>
<br />
<input type="text" id="contato_email" name="contato_email" size="30" value="<? print $contato_email; ?>" />
<br />
<label for="produto">Produto <span class="required">*</span></label>
<br />
<input type="text" id="produto" name="produto" size="30" value="<? print $produto; ?>" />
<br />
<label for="origem">Origem <span class="required">*</span></label>
<br />
<input type="text" id="origem" name="origem" size="30" value="<? print $origem ?>" />
<br />
<label for="destino">Destino <span class="required">*</span></label>
<br />
<input type="text" id="destino" name="destino" size="30" value="<? print $destino; ?>" />
<br />
<label for="quantidade">Quantidade <span class="required">*</span></label>
<br />
<input type="text" id="quantidade" name="quantidade" size="30" value="<? print $quantidade; ?>" />
<br />
<label for="peso">Peso <span class="required">*</span></label>
<br />
<input type="text" id="peso" name="peso" size="30" value="<? print $peso; ?>" />
<br />
<label for="comprimento">Comprimento <span class="required">*</span></label>
<br />
<input type="text" id="comprimento" name="comprimento" size="30" value="<? print $comprimento; ?>" />
<br />
<label for="altura">Altura <span class="required">*</span></label>
<br />
<input type="text" id="altura" name="altura" size="30" value="<? print $altura; ?>" />
<br />
<label for="largura">Largura <span class="required">*</span></label>
<br />
<input type="text" id="largura" name="largura" size="30" value="<? print $largura; ?>" />
<br />
</fieldset>
<input type="hidden" name="sendcontact" value="contactsent" />
<input type="submit" value="Enviar" />
</form> 
 
-- 
Best regards,
 Luc
________________________

Powered by The Bat! version 3.99.3 with Windows XP (build 2600),
version 5.1 Service Pack 2 and using the best browser: Opera.

"Experience - the name men give to their mistakes." - Oscar Wilde.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux