PHP How to Display HTML Code in a Form – Display HTML code instead of output

1 CommentRSS Site FeedAuthor: AITpro Admin
Published: March 11, 2011
Updated: March 20, 2011

To display HTML code in a form instead of processing or outputting the HTML code, or to be more technically correct the HTML special characters, you would use the PHP htmlspecialchars( ) string function.  If you want to display all  HTML character entities then y0u would use the htmlentities( ) string function instead

How to display HTML code in a form and not process or output the HTML code:

In this form example the form has a text field where YouTube embed code is allowed to be entered to display a YouTube video in a directory listing submission.  The HTML code needs to be displayed instead of allowing PHP to process the HTML code becaue the submit form is re-editable.  What happens if you don’t display the actual HTML code instead of allowing the code to be processed or ouputted is that the YouTube embed code will display the video in the submit form if a person is re-editing their directory listing submission.  So the goal is to have the actual YouTube HTML embed code be displayed instead of allowing the HTML code to be processed or outputted and display the actual Youtube video on re-edit of the submit form.  This is a very simple thing to accomplish using the PHP htmlspecialchars( ) string function.

Example:

   if(isset($_POST['action']) && !isset($data) ){ echo $_POST['Dir']['youtube_url_55'];
} elseif (isset($data)){ echo htmlspecialchars($data['youtube_url_55'][0]); } ?>" />

So basically what is happening above is that the form is being checked to see if the post action is selected and if there is data entered into the text field (that portion of the form code that contains the actual text field code is not displayed in this example) and if no data is entered yet then the YouTube embed code that the form submitter enters into the text field will be echoed when the form script is processed.  Then the elseif will check to see if data already exists and if it does it will echo that data that already exists.  So here is where htmlspecialchars is important because if the user is re-editing the form and htmlspecialchars is not used then the form will display the actual YouTube video not the actual YouTube HTML embed code, which is what you want for a number of reasons.  One really obvious one would be if they wanted to change the size dimensions of the YouTube video displayed in the directory listing.  They could simple just edit the HTML code and change those dimensions without having to edit the YouTube HTML embed code outside of the form and then have to copy and paste that HTML code to the form again. 

The HTML code is displayed in the submission form on re-edit.  If the htmlspecialchars string function was not used here the user would see the actual YouTube video embedded into the form.

Click Image to Enlarge
PHP Display html Code in Form not Output


PHP code Reference Link
PHP htmlspecialchars string function

Share
The original question was regarding adding or inserting a Flash movie into Dreamweaver.  This was a question that was answered on YA and covers the basics of inserting a Flash movie into an HTML template in Dreamweaver and also other specific issues this person was having.
 
I see that there is a video recording program called Easy Video Recorder for Mac. I’m going to assume this is the correct program you are talking about because you mention recording your computer screen and inserting the video file into what I also will assume is going to be a web page if you are using Dreamweaver. The default exported format appears to be QuickTime for this program, but the EVR program does offer other formats that you can choose. The QuickTime MOV format is gigantic and is not a good format to use in website design. Flash SWF is the best video format to use in website design so you will need to convert the MOV file to an SWF file. It looks like you already did that so I am going to assume that the file conversion was successful and not corrupted.

Create a new blank HTML page in Dreamweaver.
Click on Show Code and Design Views so that you have a Split screen – showing both the Code View and the Design View in Dreamweaver.
Click anywhere in the Design View page (not Code View) and then go to the Insert Menu
Then Media, then Click on Flash.

Now look at the Code View section of the Split screen – This is very important. In the head section of the HTML page you will see that a javascript file source reference link has been added to your HTML file – see below – I cannot include the full link here because YA will not allow it of course.
script src=”DWConfiguration/ActiveContent/IncludeFiles/AC_RunActiveContent.js
You should also see the object code in the body of the HTML page where you inserted the Flash file.
So in order for your inserted Flash movie file to work you are going to need to have the AC_RunActiveContent.js file in the correct location in order for you to view the Flash movie.
When you save the new HTML file that you created for the first time 2 things will happen

1. Dreamweaver will automatically create a copy of the AC_RunActiveContent.js file and put it in the same folder location that you save the HTML file too.
2. The src link to the AC_RunActiveContent.js file in your head section will change to the actual file path where the AC_RunActiveContent.js file has been automatically created for you by Dreamweaver.

If you are not sure where that is just look at the src link in your head section.
At this point you should preview your HTML template in Dreamweaver to see if the Flash movie is working. Click the File menu and click Preview in Browser or click a shortcut menu button to preview your HTML page and Flash movie.
Hopefully everything is working correctly locally on your computer and browser.

In order for the Flash movie to play on your website you would upload the HTML file you just created, the actual Flash movie file and the AC_RunActiveContent.js file to your web host server / your website. So you need these 3 basic things in order to have a Flash movie on your website. For simplicity sake just keep all the files in the same folder until you get the hang of creating embedded Flash movies for websites, then you will want to move the different files to more appropriate folders like /scripts for example and /flash, etc. Good luck.

Share