Mike Milligan wrote:
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
titleAdd New Event/title
/head
body bgcolor=#FF
form method=get action=calendar.php
table style=border-collapse: collapse; bordercolor=#00
cellspacing=0 cellpadding=2 border=0
tr
td valign=top align=left width=18%
divEvent Date: /div/td
td valign=top
div
input type=text name=date/div/td
tdnbsp;/td/tr
tr
td valign=top align=left width=18%
divEvent Title: /div/td
td valign=top
div
input type=text name=title/div/td
tdnbsp;/td/tr
tr
td valign=top align=left width=18%
divEvent Description: /div/td
td valign=top colspan=2
divtextarea name=desc rows=15 cols=50%
/textarea/div/td/tr
tr
td valign=top align=left width=18%
divLocation: /div/td
td valign=top
div
input type=text name=place/div/td
tdnbsp;/td
tr
td valign=top align=left width=18%
divCost: /div/td
td valign=top
div
input type=text name=cost/div/td
tdnbsp;/td/tr
tr
td valign=top align=left width=18%
divAdditional Information: /div/td
td valign=top colspan=2
divtextarea 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
headtitleError/title/head
body
h1Incomplete 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 = 'strongfont color=#99 size=4 face=Arial, Helvetica,
sans-serif';
$b = '/font/strong/pblockquotepfont color=#99 face=Arial,
Helvetica, sans-serifstrongb';
$c = '/b/strong/font/ppfont color=#99 face=Arial,
Helvetica, sans-serif';
$d = '/font/ppfont color=#99 face=Arial, Helvetica,
sans-serif';
$e = 'br/fontfont color=#99 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
titleEntry Verification/title
/head
body bgcolor=#FF
h1Please check your new entry!/h1p
Correct errors by hitting your BACK button.p
?
echo $new;
?
form method=post action=calendar.php
input type=submit value=Submit
Put here this, it will passed to your next page:
input type=hidden name=new value=?php echo htmlspecialchars($new)
?
/FORM
/body
/html
?
You are writing to your file right after displaying confirmation. You
should have here:
} elseif(isset($_REQUEST['new'])) {
Don't forget to check for (non)existance of $_REQUEST['new'] where
necessary.
//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