Hallo,

Het volgende wilt niet werken.
HEt zal wel rap duidelijk zin wat de bedoeling is ....

<html>
<head>
<title>Untitled Document</title>

</head>

<body>
<?
function confirm_form($first_name, $last_name, $mail, $zip_code, $os){
print("Thanks\n");
print("Contact Info\n");
print("$first_name, $last_name \n");
print("$mail \n");
print("zip: $zip\n");
print("os: $os \n");
}

function print_form($first_name, $last_name, $mail, $zip_code, $os){?>
<table width="34%" border="2" cellspacing="0" cellpadding="0">
<form method="post">
<tr>
<td width="38%">First Name</td>
<td width="62%"><input name="first_name" type="text" value="<? print ("$first_name") ?>"></td>
</tr>
<tr>
<td>Last name*</td>
<td><input name="last_name" type="text" value="<? print $last_name ?>"></td>
</tr>
<tr>
<td>e-mail address*</td>
<td><input name="mail" type="text" value="<? print $mail ?>"></td>
</tr>
<tr>
<td>Zip-code*</td>
<td><input name="zip_code" type="text" value="<? print $zip_code ?>"></td>
</tr>
<tr>
<td>operating system</td>
<td><input name="os" type="text" value="<? print $os ?>"></td>
</tr>
</table>
<input type="submit" value="submit!">
<input type="reset" vamue="reset">
<? }

function check_form($last_name, $mail, $zip_code){
if(!$last_name && !$mail&& !$zip_code){ //waarom niet !isset($_POST["mail"]
confirm_form($first_name, $last_name, $mail, $zip_code, $os);
}
elseif(!isset($_POST["last_name"])){
print("You are missing some required fields \n");
print("you need to fill your Last name\n");
}
elseif(!isset($_POST["mail"])){
print("You are missing some required fields \n");
print("you need to fill your e-mail\n");
}
elseif(!isset($_POST["zip_code"])){
print("You are missing some required fields \n");
print("you need to fill your zip code\n");
}
print_form($last_name, $mail, $zip_code);

if(empty($_POST)){
?>Please enter your information <br>
met * verplicht in te vullen \n")<br>
<? print_form("","","","","");
} ?>
</body>
</html>
PHP is een server side taal, wat jij wil moet met javascript, dat werkt client side.
het is met php ook mogelijk, heb al meerere van zulke dingen gemaakt.

Bruno
Eigenwijs doen is ook een kunst.

PHP IS SERVER SIDE EN DIT MOET MET JAVASCRIPT WANT DAT WERKT WEL CLIENT SIDE ZOALS JIJ WIL!!!.

Of het moet zijn dat je de controle pas op de volgende pagina wil doen, dan kan het idd wel met php. Maar daar lijkt deze code totaal niet op.

Je maakt een functie om vervolgens html neer te knallen en tussendoor een paar variabelen. Dat gaat al nooit goed en is als het al zou werken overbodig om daarvoor een functie te maken...

Ik zou eerst eens wat meer over php gaan lezen want zo lukt het niet :)
En wa peisde dan van het volgende ...

<html>
<head>
<title>Untitled Document</title>

</head>

<body>
<?
function confirm_form($first_name, $last_name, $mail, $zip_code, $os){

print("Thanks <br>");
print("Contact Info <br>");
print("$first_name, $last_name <br>");
print("$mail <br>");
print("zip: $zip_code <br>");
print("os: $os <br>");
}

function print_form($first_name, $last_name, $mail, $zip_code, $os){
?>
<table width="34%" border="2" cellspacing="0" cellpadding="0">
<form method="post">
<tr>
<td width="38%">First Name</td>
<td width="62%"><input type="text" name="first_name" value="<? print ($first_name) ?>"></td>
</tr>
<tr>
<td>Last name*</td>
<td><input name="last_name" type="text" value="<? print ($last_name) ?>"></td>
</tr>
<tr>
<td>e-mail address*</td>
<td><input name="mail" type="text" value="<? print ($mail) ?>"></td>
</tr>
<tr>
<td>Zip-code*</td>
<td><input name="zip_code" type="text" value="<? print ($zip_code) ?>"></td>
</tr>
<tr>
<td>operating system</td>
<td><input name="os" type="text" value="<? print ($os) ?>"></td>
</tr>
</table>
<input type="submit" value="submit!">
<input type="reset" vamue="reset">
</form>
<? }
function check_form($first_name, $last_name, $mail, $zip_code, $os){
if(($last_name!="") && ($mail!="") && ($zip_code!="")){
confirm_form($first_name, $last_name, $mail, $zip_code, $os);
}
else{
if($last_name==""){
print("You are missing some required fields <br>");
print("you need to fill your Last name<br>");
}
if($mail==""){
print("You are missing some required fields <br>");
print("you need to fill your e-mail <br>");
}
if($zip_code==""){
print("You are missing some required fields <br>");
print("you need to fill your zip code <br>");
}
print_form($first_name, $last_name, $mail, $zip_code, $os);
}
}

//main
if(empty($_POST)){?>
Please enter your information <br>
met * verplicht in te vullen<br>
<? print_form("","","","","");
}
else {
check_form($_POST["first_name"], $_POST["last_name"], $_POST["mail"], $_POST["zip_code"], $_POST["os"]);
}
?>
</body>
</html>
Nog altijd dit:
dutchcamel schreef op 30.12.2004 12:37
Eigenwijs doen is ook een kunst.

PHP IS SERVER SIDE EN DIT MOET MET JAVASCRIPT WANT DAT WERKT WEL CLIENT SIDE ZOALS JIJ WIL!!!.

Of het moet zijn dat je de controle pas op de volgende pagina wil doen, dan kan het idd wel met php. Maar daar lijkt deze code totaal niet op.

Je maakt een functie om vervolgens html neer te knallen en tussendoor een paar variabelen. Dat gaat al nooit goed en is als het al zou werken overbodig om daarvoor een functie te maken...

Ik zou eerst eens wat meer over php gaan lezen want zo lukt het niet :)
Hou er wel rekening mee dat je JavaScript functies heel makkelijk kan spoofen.
Omdat het client-sided is, wat betekend dat de client er in kan lopen kl*t*n in je source code en dus zo je form check functie kan spoofen of uitschakelen.
Hou het dus maar lekker bij PHP ;).
Het beste is op de pagina zelf met javascript laten controleren, dat voorkomt ergernissen van de bezoeker die formulieren door 1 foutje onnodig opnieuw in moet vullen. En vervolgens op de volgende pagina alle gegevens met behulp van PHP nog eens te controleren. Een soort dubbele controle die veilig en gebruiksvriendelijk is :)
er zit zowieso een fout in het script
<input type="submit" value="submit!">
<input type="reset" vamue="reset">

vamue ???
Dat is modern scripten.
lol :)

Reageren