Jump to content

Problema afisare erori formular de contact


Recommended Posts

Posted

Salut! De curand am lucrat la un sistem de contact prin email folosind PHP si HTML. Singura problema pe care nu stiu cum sa o rezolv este atunci cand de exemplu gresesc ceva in completarea cererii si cand primesc eroarea (pop-up in browser) ma da pe pagina .php, nu inapoi in Index. Va rog ajutati-ma, multumesc!

<?php
$myemail  = "";
$yourname = check_input($_POST['yourname'], "Enter your name");
$subject  = check_input($_POST['subject'], "Write a subject");
$email    = check_input($_POST['email']);
$likeit   = check_input($_POST['likeit']);
$how_find = check_input($_POST['how']);
$comments = check_input($_POST['comments'], "Write your comments");

if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
        echo "<script type='text/javascript'>alert('Adresa de e-mail nu este valida!');</script>";
        die();
}

$message = "Sugestie/Cerere:

Nume: $yourname
E-mail: $email

Cum ne-a gasit: $how_find

Mesaj: $comments";

mail($myemail, $subject, $message);

header('Location: mail2.html');
exit();

function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <body>

    <b>Te rog corecteaza erroarea urmatoare:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php
exit();
}
?>
<form action="mail.php" method="post">
<p><b>Numele tau:</b> <input type="text" name="yourname" /></b>
<b>Subiect:</b> <input type="text" name="subject" /></b>
<b>E-mail:</b> <input type="text" name="email" /></b>

<b>Cum ne-ai gasit?:</b>

<select name="how">
<option value=""> -- Alege o varianta -- </option>
<option>Google</option>
<option>Yahoo</option>
<option>Prieteni</option>
<option>Alta modalitate</option>
</select>
<b>Mesaj:</b>
<textarea name="comments" rows="6" cols="40"></textarea></p>

<p><input type="submit" value="Trimite"></p>

</form>

P.S.: In cazul in care cererea a functionat am pus header-ul care functioneaza, dar daca il pun pentru greseli nu merge.

  • Moderators
Posted

Sintaxa in functia show_error nu este corecta deloc. Daca vrei sa te duca pe index, poti face:

function show_error($myError)
{
    header('Location: /?error=contact');
    return;
}

Si pe index poti afisa eroarea care vrei cu ceva de genu:

if (isset($_GET['error']) && !empty($_GET['error'])) {
    // Codu cu eroarea aici. Poti afisa un div sau ce vrei intr-un loc anume
}

Nu recomand totusi sa se afiseze lucrurile astea de genu, is metode mult mai bune pentru a arata o eroare.

PHP Developer - Not available for freelancing right now

Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament

  • gaby changed the title to Problema afisare erori formular de contact

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.