Creating a webpage from an HTML form via PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm have a PHP created HTML form that I want a user to be able to enter data
into, then see it as the PHP/HTML will format it, then post it to an HTML file.
 I've been trying all day to find something similar on your site, but to no
avail.

I am really new to PHP so I may not have done things the easy way.  The code
below outputs the proper data, but it does it without user concent.  I'd like
to have the user review what they typed prior to posting it to dates.htm.

Any help would be appreciated.

Thanks.

Mike

code as follows:

<?php
//-------------------------INITIALIZE VARIABLES
$filename = 'dates.htm';
$handle = fopen($filename, "rb");
$old = fread($handle, filesize($filename));
fclose($handle);
$date = $_REQUEST['date'] ;
$title = $_REQUEST['title'] ;
$desc = $_REQUEST['desc'] ;
$place = $_REQUEST['place'] ;
$cost = $_REQUEST['cost'] ;
$info = $_REQUEST['info'] ;

//-------------------------DISPLAY FORM
if (!isset($_REQUEST['date']))
   {
   ?>
   <html>
   <head>
   <title>Add New Event</title>
   </head>
   <body bgcolor="#FFFFFF">
   <form method="get" action="calendar.php">
   <table style="border-collapse: collapse;" bordercolor="#000000"
cellspacing="0" cellpadding="2" border="0">
   <tr>
   <td valign="top" align="left" width="18%">
   <div>Event Date: </div></td>
   <td valign="top">
   <div>
   <input type="text" name="date"></div></td>
   <td>&nbsp;</td></tr>
   <tr>
   <td valign="top" align="left" width="18%">
   <div>Event Title: </div></td>
   <td valign="top">
   <div>
   <input type="text" name="title"></div></td>
   <td>&nbsp;</td></tr>
   <tr>
   <td valign="top" align="left" width="18%">
   <div>Event Description: </div></td>
   <td valign="top" colspan="2">
   <div><textarea name="desc" rows="15" cols=50%>
   </textarea></div></td></tr>
   <tr>
   <td valign="top" align="left" width="18%">
   <div>Location: </div></td>
   <td valign="top">
   <div>
   <input type="text" name="place"></div></td>
   <td>&nbsp;</td>
   <tr>
   <td valign="top" align="left" width="18%">
   <div>Cost: </div></td>
   <td valign="top">
   <div>
   <input type="text" name="cost"></div></td>
   <td>&nbsp;</td></tr>
   <tr>
   <td valign="top" align="left" width="18%">
   <div>Additional Information: </div></td>
   <td valign="top" colspan="2">
   <div><textarea name="info" rows="6" cols=50%>
   </textarea></div></td></tr>
   </table>
   <input type="submit" value="Add New Event">
   <input type="reset" value="Clear Form" name="reset">
   </FORM>
   </body>
   </html>
   <?
   }

//CHECK FOR EMPTY FIELDS
elseif (empty($date) || empty($desc))
   {
   header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
   header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
   header( "Cache-Control: no-cache, must-revalidate" );
   header( "Pragma: no-cache" );
   ?>
   <html>
   <head><title>Error</title></head>
   <body>
   <h1>Incomplete Form</h1>
   <p>
   The date and description of the event are required fields.  Press your BACK
button and try again.</p>
   </body>
   </html>
   <?
   }



//-----------------------------------PROCESS FORM
elseif(!empty($date) || !empty($desc))
   {
//SET FORM VARIABLES
   $a = '<strong><font color="#666699" size="4" face="Arial, Helvetica,
sans-serif">';
   $b = '</font></strong></p><blockquote><p><font color="#666699" face="Arial,
Helvetica, sans-serif"><strong><b>';
   $c = '</b></strong></font></p><p><font color="#666699" face="Arial,
Helvetica, sans-serif">';
   $d = '</font></p><p><font color="#666699" face="Arial, Helvetica,
sans-serif">';
   $e = '<br></font><font color="#666699" face="Arial, Helvetica, sans-serif">';
   $f = '</font></p></blockquote>';

//JOIN VARIABLES
   $all = array($a,$date,$b,$title,$c,$desc,$d,$place,$e,'Price:
',$cost,$d,'Additional Information: ',$info,$f);
   $new = implode($all);
   $array = array($new,$old);
   $joined = implode($array);

//CONFIRM ADDITION
?><html>
   <head>
   <title>Entry Verification</title>
   </head>
   <body bgcolor="#FFFFFF">
   <h1>Please check your new entry!</h1><p>
   Correct errors by hitting your BACK button.<p>
   <?
   echo $new;
   ?>
   <form method="post" action="calendar.php">
   <input type="submit" value="Submit">
   </FORM>
   </body>
   </html>
   <?

//------------------------------------FILE ACCESS & WRITING
//OPEN FILE
   if (!$handle = fopen($filename, 'w'))
      {
      echo "Cannot open file ($filename)";
      exit;
      }
//WRITE TO FILE
   if (fwrite($handle, $joined) === FALSE)
      {
      echo "Cannot write to file ($filename)";
      exit;
      }
   echo "Success, wrote ($joined) to file ($filename)";
   fclose($handle);
   }
?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux