Hi someone,
First of all, let me present my self and my level of skills: I have been writing HTML (not always valid though) for about five years now on and off, and has recently dived into the wonderful world of php. The majority of the scripts I use run on the pages I will be presenting in this forum are copyed, written off or based upon/tested based on the scripts I’ve found. So eventhough the scripts has got a couple of advanced skill properties, does not indicate that I am a skilled php programmer… So there you have it…
Here’s my case:
I have a simple form at this adress:
http://www.tvnt.no/nytipsform/tips-del1.php
(In Norwegian, but shouldn’t really matter…)
Obviously you’ll notice that every field in the form has a predifined value i.e. using the value=“Emne” in the input tag. This is for space efficiency
Now, to the mindwobbler:
I am trying to make a script (as earlier mentioned: Based upon the existing code I’ve found for validation) that can verify that the form is not being sent with the standard values… I.e. Where Emne (Subject) is not “Emne” or Navn (Name) is not “Ditt Navn” (“Your name”)…
Here’s the code from the php-file
(I don’t know which part you will be needing for the troubleshooting so I’m pasting the whole file in this post. Sorry for this… And PLEASE, comment on what I’m asking about only! I know the code might be a bit messy, but most of the code is working the way I want it to.)
[code]
Tips oss <?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; ?> </div>
<div id="tipbubblebg-message">
<div id="tipbubble-message">
Sett inn <b>beskjed</b> her...
</div>
</div>
<div id="button1div">
<input id="resetbutton" type="reset" name="Reset" value="Angre" onfocus="this.blur();" />
</div>
<div id="button2div">
<input id="submitbutton" type="submit" name="Submit" value="Send" onfocus="this.blur();" />
</div>
</div>
<div id="validationmarks">
<a href="http://jigsaw.w3.org/css-validator/">
<img style="border:0;width:88px;height:31px"
src="http://jigsaw.w3.org/css-validator/images/vcss"
alt="Valid CSS!" />
</a>
<a href="http://validator.w3.org/check?uri=referer">
<img style="border:0;width:88px;height:31px"
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Transitional" />
</a>
</div>
</form>
<?php
} else {
// initialize a variable to
// put any errors we encounter into an array
$errors = array();
// test to see if the form was actually
// posted from our form
$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
//puts illegal values in variables
$illegalSubject = 'Emne';
$illegalName = 'Ditt Navn';
$illegalMail = 'din@mailadresse';
$illegalCity = 'By / kommune';
$illegalTel = 'Telefonnummer';
$illegalMessage = 'Din beskjed';
if (!ereg($page, $_SERVER['HTTP_REFERER']))
$errors[] = "Ugyldig referanseskjema!n";
// check to see if a name was entered
if (!$_POST['Name'])
// if not, add that error to our array
$errors[] = "Feltet "Ditt Navn" kan ikke v?re tomt!";
/*[/code]
Here’s the code that I can’t udnerstand! How to check if $_POST[‘Name’] equals $illegalName and outputting the error to the $errors[] array???
[code]
*/
if (!$_POST[‘Name’] == $illegalName )
$errors[] = “Feltet “Ditt Navn” kan ikke fylles ut med standardverdien “Ditt Navn”!”;
if (!$_POST['Subject'])
// if not, add that error to our array
$errors[] = "Emne er et obligatorisk felt!";
// check to see if a subject was entered
if (!$_POST['Tel'])
// if not, add that error to our array
$errors[] = "Telefonnummer er et obligatorisk felt!";
// check to see if a message was entered
if (!$_POST['Message'])
// if not, add that error to our array
$errors[] = "Din beskjed er et obligatorisk felt!";
// if there are any errors, display them
if (count($errors)>0){
echo "<p id="header">FØLGENDE FEIL OPPSTO:</p>n<p id="error">";
foreach($errors as $err)
echo "$err<br>n";
echo "</p>";
} else {
error_reporting(0);
$recipent = '[email protected]';
$subject = "Fra tvnt.no tipsskjema [".$_POST['Subject']."]";
$fromname = ucwords(stripslashes($_POST['Name']));
$frommail = $_POST['Mail'];
$city = $_POST['City'];
$tel = $_POST['Tel'];
$sender = "From: ".$fromname." <".$frommail.">rn";
$message = "Tips fra $fromname fra $citynnKontaktinformasjon:nTelefonnummer: $telnE-post-adresse: $frommailnnBeskjed:n".stripslashes($_POST['Message']);
$message = convert_cyr_string($message,'d','w');
$message = wordwrap($message, 70);
$message = strtr($message,"|+"," ?");
if(mail($recipent, $subject, $message, $sender))
echo ("<p id="header">").strtoupper("Beskjeden er sendt").nl2br(".</p><p>
<b>Tusen takk for ditt tips!</b>
Til: Redaksjonen, TVNord-Trøndelag < $recipent >
Emne: $subject
$message
</p>");
else
echo("
<p><b>Beklager!</b>
<br />Beskjeden kunne ikke leveres!
<br />Dette kan skyldes en intern feil eller en serverfeil.
</p>
<p>
<b>Vennligst prøv igjen senere.</b>
</p>
<p id="dimtext">Hvis du ønsker å rapportere feilen,
<br />send da en e-post til <a href="mailto:[email protected]">[email protected]</a>
</p>
");
}
}
?>
[/code]