Hi All, I have and existing website (HTML, created with DW). I have a PHP form I want to embed into HTML file. problem is that PHP file also has HEAD and BODY tags, and I dont know how to do it right, the PHP form display in the HTML but with many errors and its not working. will appreciate your help, thanks, Kobi the PHP code I have is: <?php include_once( "form.lib.php" ); ?> <html style="direction: rtl; lang="he"> <head> <title>Free Form Maker - PHP Forms</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <meta name="keywords" content="free forms php form maker"> <meta name="description" content="build php forms with unlimited fields automatic validation, file attachments and auto-responder."> <style type='text/css'> .form_title{ color : #000000; font-size: 13px; font-family: verdana, Geneva, Arial, Helvetica, sans-serif; font-weight : bold; } .form_field { font-size : 13px; font-family : Verdana, Arial, Helvetica, sans-serif; color : #474747; font-weight : bold; text-align:left; } .form_text{ font-size : 11px; font-family : "Times New Roman", serif; color : #000000; } .text_box{ font-size : 11px; font-family : "Times New Roman", serif; color : #000000; width:200px; } .text_area{ font-size : 11px; font-family : "Times New Roman", serif; color : #000000; width:200px; height:60px; } .text_select{ font-size : 11px; font-family : "Times New Roman", serif; color : #000000; } .form_error{ font-size : 11px; font-family : "Times New Roman", serif; color : #ff0000; font-weight : bold; } .copyright{ font-size : 11px; font-family : "Times New Roman", serif; color : #000000; } </style> </head> <body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0"> <center> <meta http-equiv="content-type" content="text/html; charset="> <!-- Begin: Form Description --> <br><br><br> <table cellspacing='16' cellpadding='0' border='0' align='center' ><tr><td> <font class='form_title'></font> </td></tr></table> <!-- End: Your FormMail's Description --> <!-- Begin: Form --> <?php if( !$isHideForm ): global $sErr ; if( $sErr ) print "<br><a name='error'></a><center><font class='form_error' >$sErr</font></center><br>"; $starColor = $sErr ? "#ff0000" : "#000000"; $style=" class='form_text' "; ?> <form name="frmFormMail" action="<?php print PHP_SELF ?>" method='post' enctype='multipart/form-data'> <input type='hidden' name='formmail_submit' value='Y'> <input type='hidden' name='esh_formmail_subject' value="Mail From GIDIWALTER.com"> <input type='hidden' name='esh_formmail_return_subject' value="response header"> <input type='hidden' name='esh_formmail_return_msg' value="response text. response text second line. "> <table cellspacing='16' cellpadding='0' border='0' > <tr> <td class="form_field" valign='top' align='right'>name </td><td width='10' aligh='right' valign='top'></td> <td class="form_text"> <input type="text" name="name" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "name" ] ); ?>" class='text_box'> </td> </tr> <tr> <td class="form_field" valign='top' align='right'>telephone </td><td width='10' aligh='right' valign='top'></td> <td class="form_text"> <input type="text" name="telephone" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "telephone" ] ); ?>" class='text_box'> </td> </tr> <tr> <td class="form_field" valign='top' align='right'>email </td><td width='10' aligh='right' valign='top'></td> <td class="form_text"> <input type="email" name="email" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "email" ] ); ?>" class='text_box'> </td> </tr> <tr> <td class="form_field" valign='top' align='right'>date </td><td width='10' aligh='right' valign='top'></td> <td class="form_text"> <?php selectList( "date_DD", $HTTP_POST_VARS["date_DD"], 1, 31, "יו×", $style ) ; selectList( "date_MM", $HTTP_POST_VARS["date_MM"], 1, 12, "חודש", $style ) ; selectList( "date_YYYY", $HTTP_POST_VARS["date_YYYY"], date("Y"), date("Y")+3, "×©× ×”", $style ) ; ?> </td> </tr> <tr> <td class="form_field" valign='top' align='right'>time </td><td width='10' aligh='right' valign='top'></td> <td class="form_text"> <?php selectList( "time_HH", $HTTP_POST_VARS["time_HH"], 0, 23, "שעה", $style ) ; selectList( "time_MM", $HTTP_POST_VARS["time_MM"], 0, 59, "דקות", $style ) ; ?> </td> </tr> <tr> <td class="form_field" valign='top' align='right'>message </td><td width='10' aligh='right' valign='top'></td> <td class="form_text"> <textarea name="message" rows=4 cols=25 ><?php print HtmlSpecialChars( $HTTP_POST_VARS[ "message" ] ); ?></textarea> </td> </tr> <tr><td colspan=3 align='center'><input type='submit' value='שלח'> <input type='button' value='מחק' onclick="location.href='/';"></td></tr> </table> </form> <!-- End: --> <?php if( $sErr ) print "<script language='javascript' type='text/javascript'>location.href='#error';</script>";;; else: //!$isHideForm print( "<br><br><hr><center><b>Your form has been sent. Thank you.</b><br><br><input type='button' value='Home' onclick=\"location.href='/';\"></center><br><br>" ); endif; //!$isHideForm ?> <!-- footer --> <br /><br /> <p> </p> </center> </body> </html> PHP:
First: you cannot run PHP-code from within a HTML file, unless your server is set up to also parse html-files as php (most likely it wouldn't be). Second: have you tried doing the other way around? Put whatever else you need from the existing html-file into the PHP-file?
thanks for your reply, 1. I put the PHP into blank HTML file and its lookk like this : http://www.vote2poll.com/wg/left/test.html so I thought I can work with further help.. 2. I cant use a stand alone PHP file since there is a whole website working already, I just want to add this web form
PHP-code won't work in a file with the filetype/extension .html. No way. Unless someone has configured the server to read .html-files as .php-files, and then parse them - but that would be really really stupid, and not recommended. Unless you change the filename to .php, it won't work. You don't have to change the whole site, just the one page where you want the form to be. There isn't a problem using .html and .php files at the same time.
Not the best thing to do, but try adding this line to your root .htaccess to parse html as php: AddType application/x-httpd-php .html Code (markup): Should work if your host supports "AddType" in .htaccess. Regards, Dennis M.
amazing, I just rename the file extension to .php and it works like magic. how can it be, isnt HTM and PHP 2 different languages? now I wonder if I should do that to all of the page? is there any risk by doing it? or any advantages? also, how can I make a checkbox unchecked by default: <input type="checkbox" name="Checkbox01_alternative_car" value="" <?php formChecked( $HTTP_POST_VARS[ "Checkbox01_alternative_car" ], "" ); ?> > many thnaks to you two, Kobi
You could do it to all pages, no problem. There isn't really a point in doing it though, unless you are using PHP in those pages. HTML is being parsed directly by the webserver, fairly quickly (depending on the amount of dynamic scripting (javascript and the like) on the page). PHP-files are parsed by PHP and then sent to the webserver for displaying whatever result (or error). This isn't really noticeable on smaller sites, but if the pages start to grow in size, this extra parsing by the PHP parser on pages where it isn't really necessary isn't recommended. And, yes, PHP and HTML are to different languages, but PHP can do everything HTML can do, and more. PHP is mostly used for two things: delivering dynamic content to webpages, eg. printing information from databases to webpages, and second: to run things in the background - form processing, data editing etc.