/ Forside / Teknologi / Udvikling / PHP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
PHP
#NavnPoint
rfh 3959
natmaden 3372
poul_from 3310
funbreak 2700
stone47 2230
Jin2k 1960
Angband 1743
Bjerner 1249
refi 1185
10  Interkril.. 1146
Validering af form med PHP
Fra : DiceMan


Dato : 21-12-01 21:11

Det er helt i orden at svare på dansk, skrev bare på engelsk da det er
mit dagligdagssprog

I'm new in the PHP world and therefore run into a problem with
validation of forms. I need to validate a form for e-mail and some
other stuff, before it being sent to a mail address.

The validation need to be shown I the form, written with a red font. A
little like this:

E-mail: <red>information is missing or incorrect</red>
[ box ]

At the moment to form and the validation are in different pages
looking like this (if somebody would write it into one page, please do
so):

-----

Form page (subscribe.html):


<html>

   <head>

      <title>Subscribe</title>
      <link href="../css/style.css" rel="styleSheet" type="text/css">
   </head>

   <script>
function loadframe(FileName)
{
parent.menu.location.replace(FileName);
}
function loadtopframe()
{
parent.topframe.location.replace('topnavi.html');

}
</script>

   <body bgcolor="white" link="#000080" alink="#000080" vlink="#000080"
background="../grafx/gen/contentbg.gif"
onload="javascript:loadframe('menu.html');
javascript:loadtopframe();">
      <a name="top"></a>
      <table border="0" cellpadding="0" cellspacing="10">
         <tr>
            <td width="390" valign="top">
               <table border="0" cellpadding="0" cellspacing="0" width="100%">
                  <tr>
                     <td valign="bottom"><span
class="headline">Subscribe</span></td>
                     <td align="right"><img height="25" width="25"
src="../grafx/gen/logosmall.gif"></td>
                  </tr>
                  <tr height="1">
                     <td height="1" colspan="2" bgcolor="#333333"><img height="1"
width="1" src="../grafx/gen/spacer.gif"></td>
                  </tr>
                  <tr height="5">
                     <td height="5"><img height="1" width="1"
src="../grafx/gen/spacer.gif"></td>
                     <td height="5"></td>
                  </tr>
               </table>
<FORM METHOD="POST" ACTION="subscribe.php">
<table border="0" width="100%">
<tr>
<td width="100%" colspan="2"
bgcolor="#E6E4D8"><font face="Arial" size="2"><b>Fill
out&nbsp; the form to
subscribe:</b></font></td>
</tr>
<tr>
<td width="11%" align="right">
<br>
</td>
<td width="89%">
<br>
</td>
</tr>
<tr>
<td width="11%" align="right"><span
class="bread">Name*:&nbsp;
</span>
</td>
<td width="89%"><span class="bread">
<INPUT NAME="name" size="25">
</span>
</td>
</tr>
<tr>
<td width="11%" align="right"><span
class="bread">Title:&nbsp;
</span>
</td>
<td width="89%"><span
class="bread"><INPUT NAME="title" size="25">
</span>
</td>
</tr>
<tr>
<td width="11%" align="right"><span
class="bread">Company:&nbsp;
</span>
</td>
<td width="89%"><span
class="bread"><INPUT NAME="company" size="25">
</span>
</td>
</tr>
<tr>
<td width="11%" align="right"><span
class="bread">
Address*:&nbsp;
</span>
</td>
<td width="89%"><span
class="bread"><INPUT NAME="address" size="25">
</span>
</td>
</tr>
<tr>
<td width="11%" align="center"><span
class="bread">
Postcode*:&nbsp;
</span>
</td>
<td width="89%"><span
class="bread"><INPUT NAME="postcode" TYPE="TEXT" SIZE="4">&nbsp;&nbsp;
City/Town: <INPUT NAME="city"
size="11">
</span>
</td>
</tr>
<tr>
<td width="11%" align="center"><span
class="bread">
Country*:&nbsp;
</span>
</td>
<td width="89%"><span class="bread">
<INPUT NAME="country" size="25">
</span>
</td>
</tr>
<tr>

<td align="right"><span
class="bread">E-mail:&nbsp;
</span>
</td>
<td>

<span class="bread"> <INPUT NAME="email"
size="30">
</span>
</td>
</tr>
<tr>
<td width="11%"
align="center">&nbsp;</td>
<td width="89%"><span
class="bread"><INPUT TYPE="SUBMIT" VALUE="Submit"></span>
</td>
</tr>
<tr>
<td width="100%" colspan="2"><span
class="bread"><br>
Please note!&nbsp;<br>
All fields marked with an asterisk(*) are required. </span></td>
</tr>
</table>
</form>
&nbsp;
</td>
            <td width="193" valign="top">
<p align="center"><img height="25" width="1"
src="../grafx/gen/spacer.gif"><br>
<img border="0" src="../images/photos/news01.gif"
width="140" height="105"></p>
</td>
         </tr>
         <tr>
            <td colspan="2"><img height="50" width="593"
src="../grafx/gen/footer.gif" border="0" usemap="#footermap"><map
name="footermap"><area href="#top" coords="526,4,569,14"
shape="rect"></map></td>
         </tr>
      </table>
   </body>

</html>

-----

Validation page (subscribe.php):

<html>

   <head>
      <title>Thank you for your interest</title>
      <link href="../css/style.css" rel="styleSheet" type="text/css">
   </head>

   <body background="../grafx/gen/contentbg.gif">
      <a name="top"></a>
      <table border="0" cellpadding="0" cellspacing="10" width="635">
         <tr>
            <td width="571" valign="top">
               <table border="0" cellpadding="0" cellspacing="0" width="561">
                  <tr>
                     <td valign="bottom" width="334"><span
class="headline">Subscription</span></td>
                     <td align="right" width="223"><img
src="../grafx/gen/logosmall.gif" width="25" height="25"></td>
                  </tr>
                  <tr height="1">
                     <td height="1" colspan="2" bgcolor="#333333" width="559"><img
src="../grafx/gen/spacer.gif" width="1" height="1"></td>
                  </tr>
                  <tr height="5">
                     <td height="5" width="334"><img src="../grafx/gen/spacer.gif"
width="1" height="1"></td>
                     <td height="5" width="223"></td>
                  </tr>
               </table>

<span class="bread"><p>Thank you for your
interest.&nbsp;

<?php
//subscribe.php
$mail_to = "sub@noname.com";
$mail_subject = "Subscribe";
$mail_body = "Name: $name\n";
$mail_body .= "Title: $title\n";
$mail_body .= "Company: $company\n";
$mail_body .= "Address: $address\n";
$mail_body .= "Postcode: $postcode \n";
$mail_body .= "City: $city\n";
$mail_body .= "Country: $country\n";
$mail_body .= "E-mail: $email\n\n";
$mail_body .= "Please send info to the person above\n";

if (mail($mail_to, $mail_subject, $mail_body))
echo "In the future you will receive our info by post.\n
If you change your address or want to unsubscribe please e-mail us at
sub@noname.com";
else echo "Unfortunately there was a problem in
the process of sending your request. Please try again or contact us
through
mail or phone and we will send you the information you are interested
in."
?>
</p>
<p>&nbsp;</p>
<p align="center">&nbsp;<a
href="content.html">Go to the info</a></p>
</span>
</td>
            <td width="30" valign="top"><img height="25" width="1"
src="../grafx/gen/spacer.gif"><br>
<br>
               <br>
</td>
         </tr>
         <tr>
            <td colspan="2" width="613"><img src="../grafx/gen/footer.gif"
border="0" usemap="#footermap" width="593" height="50"><map
name="footermap"><area href="#top" coords="526,4,569,14"
shape="rect"></map></td>
         </tr>
      </table>
</body>

-----

I hope somebody out there have some time to help me, the code is for a
school assignment.
As I said I don't have much routine in PHP, so if you have the time I
would prefer a complete code, but anything would be of help

Best regards

DiceMan

 
 
Søg
Reklame
Statistik
Spørgsmål : 177560
Tips : 31968
Nyheder : 719565
Indlæg : 6408941
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste