Jump to content

Is there something like innerHTML in PHP?


benjaminmorgan

Recommended Posts

You can add content to a html webpage with a CMS (content management system) where certain areas of code are made available by a separate username and password for editing (often by untrained people) so that the rest of teh page code cannot be altered.

 

A simple cms would be http://www.simplecms.com/

or Joomla or Drupal fro a professional cms.

 

If you want to edit a part of a page yourself without opening the whole page code, you can put your extra text or image in a separate file called an "include" file and named, say, text2.inc and code PHP in the main page where you want it inserted:-

<?php include ("text2.inc"); ?>

and the main page must have a .php extension, not .html or .htm

Edited by Wickham
Link to comment
Share on other sites

Oh, i meant like with a form. After the form is processed i want to be able to leave a message on the page without having to make it a php file and add php code to the page that the form is on.

 

Right now I am having to add the PHP code and make the form a php page. then I am using if($_GET['complete'] == true) { blah blah blah } but It is just in the middle of my content. I want to be able to do something like you could in javascript without having to rely on javascript.

Link to comment
Share on other sites

Oh, i meant like with a form. After the form is processed i want to be able to leave a message on the page without having to make it a php file and add php code to the page that the form is on.

 

Right now I am having to add the PHP code and make the form a php page. then I am using if($_GET['complete'] == true) { blah blah blah } but It is just in the middle of my content. I want to be able to do something like you could in javascript without having to rely on javascript.

 

You have to use a php form code for the message after an email is sent. Javascript might be able to do it, but my javascript knowledge is too little.

Link to comment
Share on other sites

Oh, i meant like with a form. After the form is processed i want to be able to leave a message on the page without having to make it a php file and add php code to the page that the form is on.

 

Right now I am having to add the PHP code and make the form a php page. then I am using if($_GET['complete'] == true) { blah blah blah } but It is just in the middle of my content. I want to be able to do something like you could in javascript without having to rely on javascript.

I suppose you could do your if statement then store your message in a variable.

<?php
$message="";
if(isset($_GET['complete']))
 $message="<div class='success'>Action was completed successfully</div>";
include(yourpage.php)

Then output the variable on the HTML page.

<html>
<body>
<?php echo $message; ?>
<form method='post' action=''>
...

Another thing you could do is have the HTML page read by php and have "placeholders" that will be replaced by php variables.

Then output that to the user.

Link to comment
Share on other sites

  • 1 month later...

jQuery would be your best bet for something like this, for example if you had a page with div id "main" in which you wanted to display your content and a text file called 'main-content.txt' the entire code to display this (after including jQuery on your page) would be:

 


//  *the $(document).ready(function() { part is only included once per page*

$(document).ready(function() {

$('#main').load('/path/to/main-content.txt');

});

Link to comment
Share on other sites

You could have two pages almost the same one with the massage and one without. Then have the submit button redirect to the page with the success massage added. But that would just be silly. You know javascript and php it just seems like you are trying to reinvent the wheel.

 

By the way how did the contest go on your prom thing?

Link to comment
Share on other sites

I think the fundamental answer you're looking for is... no.

 

You can't use PHP in a non-PHP 'page', or 'document', e.g. blah.html, in the way that you can write JS in a non-JS document, e.g. blah.html.

 

This is the difference between a 'script' language (JS) and a 'text-processing' language (PHP, ASP, and the others), so to speak.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...