2012-06-27 5 views
1

나는 모든 개인 정보를 입력해야하는 등록 양식을 만들었습니다. 제출하면 오류가 발생하여 모든 양식이 비어있게되므로 다시 입력해야합니다. 어떻게 이것을 막고 서있는 모든 곳에 머무르게합니까? 사전에유효성 확인 후 PHP 양식이 비어 있습니다.

<html> 
<head> 
    <title>Westpop</title> 
    <link rel="stylesheet" href="opmaak.css"> 
</head> 
<body> 
<fblack> 
<div id="header"><a href="Index.php"></a></div> 

<div id="registreer"> 
<table cellpadding="5" align="center"> 
<th colspan="2" align="left">Registeren</th> 
<form name="registreren" method="post" action="registreer.php"> 
<tr> 
    <td><fblackbold>Inloggegevens:<fblackbold></td> 
</tr> 

<tr> 
    <td>Email</td> 
    <td><input type="text" size="50" placeholder="[email protected]" name="email"></td> 
</tr> 
<tr> 
    <td>Wachtwoord</td> 
    <td><input type="password" size="50" placeholder="min. 8 tekens, 1 hoofdletter, 1 cijfer" name="wachtwoord"></td> 
</tr> 
<tr> 
    <td><fblackbold>Persoonlijke gegevens:<fblackbold></td> 
</tr> 
<tr> 
    <td>Voornaam</td> 
    <td><input type="text" size="50" placeholder="" name="voornaam" ></td> 
</tr> 
<tr> 
    <td>Achternaam</td> 
    <td><input type="text" size="50" placeholder="" name="achternaam"></td> 
</tr> 
<tr> 
    <td>Geboorte Datum</td> 
    <td><input type="hidden" size="8" name="action" value="submitform" /> 
    <input type="text" size="50" placeholder="jjjj-mm-dd" name="geboortedatum"></td> 

</tr> 
<tr> 
    <td>Geslacht</td> 
    <td>M<input type="radio" size="50" value="m" name="geslacht"> 
    V<input type="radio" size="50" value="v" name="geslacht"></td> 

</tr> 
<tr> 
    <td>Adres</td> 
    <td><input type="text" size="50" placeholder="Straat 00" name="adres"></td> 
</tr> 
<tr> 
    <td>Woonplaats</td> 
    <td><input type="text" size="50" placeholder="" name="woonplaats"></td> 
</tr> 

<tr> 
    <td>Telefoonnummer</td> 
    <td><input type="text" size="50" placeholder="min. 9 tekens" name="telefoonnummer"></td> 
</tr> 
<tr> 
    <td>Functie</td> 
    <td><select name="functie"> 
<option value="catering">Catering</option> 
<option value="muziekpodia">Muziek en podia</option> 
<option value="vervoerovernachten">Vervoer en overnachten</option> 
<option value="logistiekbeveiliging">Logistiek en beveiliging</option> 
<option value="diversen">Diversen</option> 
</select></td> 
</tr> 
<tr align="right"> 
    <td></td> 
    <td><input type="reset" value="Wissen"><input type="submit" name="verzenden" value="Verzenden"></td> 
</tr> 
</form> 
</table> 
<?php 
if (isset($_POST['action']) && $_POST['action']=='submitform') { 


    $host = "localhost"; 
    $gebruikersnaam = "root"; 
    $wachtwoord = ""; 
    mysql_connect($host, $gebruikersnaam, $wachtwoord); 

    $demooistedatabase = "c5g4westpopintranet"; 
    mysql_select_db($demooistedatabase); 

    $achternaam = $_POST["achternaam"]; 
    $voornaam = $_POST["voornaam"]; 
    $gbdatum = $_POST["geboortedatum"]; 
    $email = $_POST["email"]; 
    $geslacht = $_POST["geslacht"]; 
    $wachtwoord = $_POST["wachtwoord"]; 
    $woonplaats = $_POST["woonplaats"]; 
    $adres = $_POST["adres"]; 
    $telefoonnummer = $_POST["telefoonnummer"]; 
    $functie = $_POST["functie"]; 


    $achternaam = stripslashes($achternaam); 
    $voornaam = stripslashes($voornaam); 
    $gbdatum = stripslashes($gbdatum); 
    $email = stripslashes($email); 
    $geslacht = stripslashes($geslacht); 
    $wachtwoord = stripslashes($wachtwoord); 
    $woonplaats = stripslashes($woonplaats); 
    $adres = stripslashes($adres); 
    $telefoonnummer = stripslashes($telefoonnummer); 
    $functie = stripslashes($functie); 


    $query ="INSERT INTO vrijwilliger (voornaam, achternaam, gbdatum, geslacht, wachtwoord, woonplaats, adres, telefoonnummer, functie, activiteitID, groepID, email) 
       VALUES('$voornaam','$achternaam','$gbdatum','$geslacht','$wachtwoord','$woonplaats','$adres','$telefoonnummer','$functie',null,null,'$email')"; 

$foutloos=true; 


if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $wachtwoord) === 0) 
{ 
echo '<fblack>Wachtwoord moet minstens 8 tekens lang zijn, een kleine letter, grote letter en cijfer bevatten.<br><fblack>'; 
$foutloos = false; 
} 

if(preg_match("/^[0-9]{10}+$/", $telefoonnummer) === 0) 
{ 
echo '<fblack>Het telefoonnummer moet 10 cijfers bevatten.<br><fblack>'; 
$foutloos = false; 
} 


if(preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/", $gbdatum) === 0) 
{ 
echo '<fblack>Geboorte datum moet op dit formaat ingevoerd worden: JJJJ-MM-DD<br><fblack>'; 
$foutloos = false; 
} 

if(preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $email) === 0) 
{ 
echo '<fblack>Email moet hier op lijken: [email protected]<br><fblack>'; 
$foutloos = false; 
} 


if(preg_match("/^[A-Z][a-zA-Z -]+$/", $voornaam) === 0) 
{ 
echo '<fblack>Voornaam is niet geldig ingevoerd, heeft u een hoofdletter gebruikt?<br><fblack>'; 
$foutloos = false; 
} 


if(preg_match("/^[A-Z][a-zA-Z -]+$/", $achternaam) === 0) 
{ 
echo '<fblack>Achternaam is niet geldig ingevoerd, heeft u een hoofdletter gebruikt?<br><fblack>'; 
$foutloos = false; 
} 


if ($geslacht == '') 
{ 
echo '<fblack>U heeft uw geslacht niet aangegeven.<br><fblack>'; 
$foutloos = false; 
} 


if(preg_match("/^[a-zA-Z]+\ +[0-9]+$/", $adres) === 0) 
{ 
echo '<fblack>Het adres is verkeerd ingevoerd.<br><fblack>'; 
$foutloos = false; 
} 


if(preg_match("/^[a-zA-Z\s]+$/", $woonplaats) === 0) 
{ 
echo '<fblack>De woonplaats is verkeerd ingevoerd.<br><fblack>'; 
$foutloos = false; 
} 

if ($foutloos == true) 
{ 
mysql_query($query) 
or die('<fblack>U staat al in ons systeem<A HREF="javascript:javascript:history.go(-1)"><br><br>Klik hier om terug te gaan</A><fblack>'); 
echo "<fblack>Uw registratie is succesvol verwerkt!<br>Log <a href='login.php' MEDIA=screen>hier</a> in<fblack>"; 
} 
} 
?> 
</div> 
<?php 
include ("html_end.php"); 
?> 

감사 : (암호를 제외하고 어쩌면)

이 내 코드입니다!

+0

해당 필드에 'value'가 없습니다. – jprofitt

+0

자바 스크립트를 사용해보세요. – Jalpesh

답변

4

당신은 같은 게시 값 에코 할 수 있습니다

<input type="text" size="50" placeholder="[email protected]" name="email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>"> 

다른 입력과 동일한 작업을 수행합니다.

+0

페이지의 유효성 확인에 도움이됩니다. 고맙습니다! –

2

양식 작업에서 값을 페이지로 다시 전달해야합니다.

페이지에서 사용할 수있게되면 값으로 설정할 수 있습니다. 예를 들면 : 당신은에 필드의 값을 설정해야

<tr> 
    <td>Email</td> 
    <td><input type="text" size="50" placeholder="[email protected]" name="email" value="<?php echo $emailEntered; ?>"></td> 
</tr> 
0

: 당신의 PHP에서

검증을하고, 값을 에코 폼에서 다음

$emailEntered = $_POST['email']; 

설정 사용자가 입력하는 값입니다.

<input type="text" size="50" placeholder="Straat 00" name="adres" value="<?php echo $_POST['adres']; ?>"> 
0

history.go(-1) (사용자가 자바 스크립트를 사용하지 않으면 작동하지 않습니다. 양식을 다시 포함하는 페이지를 생성해야합니다. 즉, HTML 코드를 form.php 파일에 넣고 잘못되었을 때 해당 파일을 포함시켜야합니다.

<input type="text" name="foo" value="<?php echo $_POST['foo']; ?>"/> 

있는 경우, 이전 값을 얻을 것이다 그런 식 :

include ('form.php'); 

if (isset($_POST) { 
    deal_with_post_data(); 

    if (something_wrong()) { 
     include('form.php'); 
    } else { 
     include('proceed.php'); 
    } 
} 

는 그리고, 양식에서 다음을 수행합니다.

그런데 stripslashes을 조심하십시오. SQL 주입을 막는 것만으로는 충분하지 않을 수도 있습니다. MySQL을 사용하고 있으므로 mysql_real_escape_string을 대신 사용하십시오.

0

브라우저는 데이터를 저장하지 않으므로 수신 한 데이터를 다시 저장해야합니다.

<?php 
$email = isset($_POST['email']) ? $_POST['email'] : ''; 
?> 
<td><input type="text" ... name="email" value="<?php echo $email; ?>"></td> 

더 복잡한 작업을 할 수 있지만 아이디어를 얻으시기 바랍니다. $ _POST에서받는 sanitaze 값을 잊지 마세요!

0

당신은 세션 변수 사용할 수 있습니다

<td><input type="text" size="50" placeholder="" name="achternaam" value="<?php echo $_SESSION["achternaam"];?>"></td> 

모든

에 동일하고 $ 쿼리 이전 형태로 페이지

<?php 
session_start(); 

//checking if variables are setted 
if !(isset($_SESSION("achternaam")){ 
    $_SESSION["achternaam"]="" 
} 
//same for all fields 

의 beggining에

을 :

0 끝에

성공하면

$_SESSION["achternaam"] = ""; 
1

대신에 일부 서버 측 오류가 발생한 후 값을 다시로드의 변수를 재설정해야하는 경우, 당신은 자바 스크립트

// HTML

를 사용하여 클라이언트 측의 필드 유효성을 검사 할 수 있습니다
// the submit button on page 
<input type="submit" name="verzenden" id= 'verzenden' value="verzenden" onclick='return validate();' /> 

// 자바 스크립트

<script type='text/javascript'> 
    function validate() 
    { 
    // check for all the text fields if they are null 
    var fname= document.getElementById('firstname'); 
    var lname= document.getElementById('lastname'); 

    if(fname.value == '') 
    { 
    // if the field is null it does not submit page and focus() function means 
    // cursor will be in that textbox 
     alert('Please enter first name'); 
     fname.focus(); 
     return false; 

    } 

    } 
</script> 
0

잘 모르겠습니다 만, 대개 내 양식의 작업이 같은 페이지에 있었기 때문에 오류가 발생하면 값 속성에 다시 값을 표시합니다. 이 사건이 아니므로, 당신은 같은 페이지에 대한 작업을 변경하고 할 같은 것을 해당 페이지의 수 :

<?php 
if (sizeof($_POST)) { 
    require 'the_action_you_have_now.php'; 
    // If it succeeds, it would redirect to another page and exit, otherwise, just continue, and set a variable with a message that says there's an error. 
} 
?> 

이 값을 설정하려면 :

value="<?php print (isset($_POST['email']) ? $_POST['email'] : '');?> 

를 또는, 따라 작동하지 않을 수 있습니다 사용자의 설정에 :

<textarea><?php print htmlentities($_POST['comment']); ?></textarea> 

<select> 
<?php 
foreach ($options as $value => $text) { 
    $selected = ($_POST['the_select'] == $value)? "selected='selected'" : ""; 
    print "<option value='$value' $selected>$text</option>"; 
} 
?> 
</select> 
:

value="<?=(isset($_POST['email']) ? $_POST['email'] : '')?> 

이것은 s와의 서로 다른 것

관련 문제