Fehlerausgabe bei Formular in PHP

Vielen Dank
Jetzt wo du das sagst, kommt es mir auch wieder in den Sinn.
Habe nur einfach zu viel überlegt und gar nicht gemerkt, dass es so einfach ist ;-)
 
Ich habe es folgendermassen gelöst,das Problem hier ist jedoch, dass die Formularfelder nicht richtig positioniert werden durch css, was ist daran falsch?:


PHP:
$error['name'] = "<font color=#990000>Your Input is incorrect!</font>"; 
$error['firstname'] = "<font color=#990000>Your Input is incorrect!</font>"; 
$error['street'] = "<font color=#990000>Your Input is incorrect!</font>"; 
$error['zip'] = "<font color=#990000>Your Input is incorrect!</font>"; 
$error['city'] = "<font color=#990000>Your Input is incorrect!</font>"; 
$error['country'] = "<font color=#990000>Your Input is incorrect!</font>"; 
$error['email'] = "<font color=#990000>Your Input is incorrect!</font>";

$fehler="
<!--All Programming, texting and graphic-work-->
<!--done by schmid-online and by Reto Bürkli-->
<!--Copyright (c)  by schmid-online.-->
<!--Reproduction in whole or in part-->
<!--in any form or medium without-->
<!--written permission is prohibited.-->
<!--Working agent - Jonas Schmid-->
<!--Contact - infos@schmid-online.ch-->
<!--schmid-online *webdesigning*designing* - www.schmid-online.ch-->

<html>

	<head>
		<meta http-equiv='content-type' content='text/html;charset=iso-8859-1'>
		<SCRIPT LANGUAGE='JavaScript' src='http://www.optimistic.ch/_php/e/js/navi.js' type='text/javascript'></SCRIPT>
		<link rel='stylesheet' href='http://www.optimistic.ch/_php/e/css/style.css' type='text/css'>
		<title>optimistic/* Ma&ntilde;ana</title>
	</head>

	<body>
		<div id='music_title'>
			<b>1 'Fast Days' E.P.</b> and the brand new Ma&ntilde;ana<br>
			single <b>'MISS EVENING' US - Dollar 18.00</b><br>
			(packaging and postage included)</div>
		
		<div id='music_text_left'>
			<b>STEP 1 - ORDER</b><br>
			
			 
			Please fill in this form to order your very own copy of<br>
			Manana&acute;s &acute;Fast Days&acute; E.P. and the band&acute;s new single<br>
			&acute;Miss Evening&acute;, featured on FIFA Soccer 2005<br>
			<br>
			<b>STEP 2 - PAY</b> (that&acute;s the way it is...)<br>
			
			Inside is a small independent label, therefore we cannot<br>
			accept credit cards or checks - sorry about that.<br>
			<br>
			But no worries - here&acute;s the easy way to pay (and the<br>
			quickest one to get your copy of the &acute;Fast Days&acute; EP):<br>
			<br>
			Please send 18.00 USD (cash, no coins) to the following<br>
			post address, including your personal data (name,<br>
			address, country and e-mail) or a copy of the ordering<br>
			form above (completed):<br>
			<br>
			inside AGENCY<br>
			Postfach 109<br>
			CH-4415 Lausen<br>
			-Switzerland-<br>
			<br>
			We will send you the Ma&ntilde;ana EP and single very soon.<br>
			Thanks a lot for supporting the band, and we hope to see<br>
			you soon at a local venue!<br>
			<br>
			Kind Regards, Ma&ntilde;ana and the inside agency team<br>
			<br>
			For further information about the band, as well as their<br>
			upcoming concerts and records, please visit<br>
			www.optimistic.ch</div>
		<div id='music_text_right'>I would like to order the following Manana recordings:<br>
			<br>
			<b>1x &acute;Fast Days E.P.&acute; (E.P., 19/12/2003)<br>
				1x &acute;Miss Evening&acute; (single, 01/11/2004)<br>
			</b><br>
			This will cost me a total of US-Dollar 18.00<br>
			(packaging and postage included).<br><br><br>

<!-- Hier kommt das Formular -->
			<form name='order' ACTION='".$PHP_SELF."' method='post'>
 <div align='center'>
 <table border='0' cellpadding='0' cellspacing='6' width='250'>
 <tr>
 <td colspan='2'>*required information (**only for the U.S.A)</td>
 </tr>";
 if ($name =="")
	echo "<tr><td></td><td>".$error['name']."</td></tr>"; 
	echo"
 <tr>
 <td>name*:</td>
 <td><input type='text' name='name' size='25' VALUE='".$name."'>
 </td>
 </tr>";
 if ($firstname =="")
	echo "<tr><td></td><td>".$error['firstname']."</td></tr>"; 
	echo"
 <tr>
 <td>first name*:</td>
 <td><input type='text' name='firstname' size='25' VALUE='".$firstname."'></td>
 </tr>";
 if ($street =="") 
	echo "<tr><td></td><td>".$error['street']."</td></tr>"; 
	echo"
 <tr>
 <td>street*:</td>
 <td><input type='text' name='street' size='25' VALUE='".$street."'></td>
 </tr>";
 if ($zip =="")
	echo "<tr><td></td><td>".$error['zip']."</td></tr>"; 
	echo"
 <tr>
 <td>zip code*:</td>
 <td><input type='text' name='zip' size='25' VALUE='".$zip."'></td>
 </tr>";
 if ($city =="") 
	echo "<tr><td></td><td>".$error['city']."</td></tr>"; 
	echo"
 <tr>
 <td>city*:</td>
 <td><input type='text' name='city' size='25' VALUE='".$city."'></td>
 </tr>
 <tr>
 <td>(state**):</td>
 <td><input type='text' name='state' size='25' VALUE='".$state."'></td>
 </tr>";
 if ($country =="")
	echo "<tr><td></td><td>".$error['country']."</td></tr>"; 
	echo"
 <tr>
 <td>country*:</td>
 <td><input type='text' name='country' size='25' VALUE='".$country."'></td>
 </tr>";
 if ($email =="") 
	echo "<tr><td></td><td>".$error['email']."</td></tr>"; 
	echo"
 <tr>
 <td>e-mail address*</td>
 <td><input type='text' name='email' size='25' VALUE='".$email."'></td>
 </tr>
 <tr>
 <td>age</td>
 <td><input type='text' name='age' size='25' VALUE='".$age."'></td>
 </tr>
  <tr>
 <td>favourite bands:</td>
 <td><input type='text' name='bands' size='25' VALUE='".$bands."'></td>
 </tr>
 <tr>
				<td>&nbsp;</td>
				<td></td>
			</tr>
 
 <tr>
 <td colspan='2' align='right'>
						Print this form (twice) and click here <input type='submit' name='submit' value='send'>
 </td>
 </tr>
 <tr>
				<td>&nbsp;</td>
				<td align='right'></td>
			</tr>
			
  <tr>
				<td>&nbsp;</td>
				<td align='right'><a href='javascript:window.close()'>fenster schliessen</a></td>
			</tr>
 </table>
 </div>
 </form>
			</div>
	</body>

</html>";

if ($name == "" || $firstname =="" || $street =="" || $zip =="" || $city =="" || $country =="" || $email ==""){
echo "$fehler";
}
else
{
mail("$webmaster","$betreffwebmaster","$koerperwebmaster\n","FROM: $absender\n"); 
}


?>
 
Robert Steichele hat gesagt.:
Das Formular muß ja so oder so selbst aufrufen, damit du die Variablen überprüfen kannst. Genau an der Stelle, wo der rote Text erscheinen soll machst du z.B. eine If-Abfrage ein, die im Fall eine falschen Eingabe einen Text (deinen Fehlertext) ausgibt. Wenn die Eingabe korrekt war, passiert nichts.
Du solltest bei der If-Abfrage noch abfragen, ob die Variable gesetzt ist, sonst erscheint die Fehlermeldung auch beim ersten Laden des Formulars.

Dies ist für mich eine gute Lösung, wenn ich nur abfragen möchte, ob die Eingabe korrekt ist. Bei mir gibt es aber Pflichtfelder, die ausgefüllt werden müssen. Das heisst ich muss abfragen können, ob die Variable gesetzt ist, wenn nicht, gibt es eine Fehlermeldung über dem Eingabefeld des Formulars. Wenn die Variable jedoch gesetzt ist, möchte ich abfragen, ob die Eingabe korrekt ist. Wenn sie nicht korrekt ist, gibt es ebenfalls eine Fehlermeldung über dem entsprechenden Eingabefeld des Formulars.
Bei meinem Formular wird bei submit eine externe PHP Datei aufgerufen, wo alles abgefragt wird und wenn alles korrekt eingegeben wurde, werden die Daten per email an mich gesendet. Ich möchte jedoch nicht in der externen Datei das ganze Formular noch einmal per echo Befehl ausgeben. Gibt es da irgendwie eine Möglichkeit mein Problem zu lösen?

Gruss Jonas
 
Hallo Jonas,

entschuldige bitte, in meinem gesterigen Eintrag ging ich eigentlich davon aus, dass Du schon erfahren in PHP bist.

Heute Nacht nehme ich mir ein wenig Zeit, um es Dir zu erklären. Im Moment geht es allerdings nicht.

Beste Grüße aus Gütersloh,
Claus
 
Hallo Claus
Vielen Dank erst einmal für deine Bemühungen. Bei mir ist es so, dass ich in letzter Zeit sehr viel gelesen, das heisst theoretisch gelernt habe und erst jetzt langsam anfange alles einzusetzen. Darum bin ich noch sehr sehr unsicher im praktischen Anweden in php. Ich habe doch noch eine Lösung gefunden.

Ich habe jetzt doch noch eine Frage:

In meinem PHP Script schreibe ich
if($submit)...
Ich finde jedoch den submitt button beim Formular sehr hässlich und würde den gerne durch text ersetzen. In JavaScript gibt es ja eine Methode, doch bei erkennt das PHP Script diesen JavaScript Befehl nicht als Submitt.
Gibt es da in PHP eine Lösung oder sonst irgend eine Art dieses Problem zu lösen?

Vielen Dank für alles
Gruss Jonas
 
So, hier mal ein kleiner Ansatz, kurz kopiert und nicht groß dokumentiert:

HTML:
echo("<form name=\"AuthForm\" style=\"display:inline;\" method=\"post\" action=\"$PHP_SELF?auth=1&key=$eb_1&lang=$lang\">");
echo("Neue Bezeichnung:&nbsp;&nbsp; <input type=\"text\" value=\"$name\" name=\"bezeichnung\" maxlength=\"100\">
<input type=\"hidden\" name=\"update_eb_1\" value=\"1\">");
echo("<br \>
<img src=\"pfeil.gif\"> <a href=\"javascript: document.AuthForm.submit()\">&Auml;nderungen speichern</a> <br \>
<img src=\"pfeil.gif\"> <a href=\"$PHP_SELF?auth=1&lang=$lang\">Abbruch</a>");

Später dann einfach update_eb_1 auswerten. Wenn == 1, dann... :)


Beste Grüße aus Gütersloh,
Claus
 
Zurück