I am trying to create a news page for a pharma website.
I have created a news article "creation" page that allows a user to input information such as author, description, and body.
The code looks like this.
<html>
<body>
<style>
textarea
{
resize: none;
}
</style>
<form action="foo.php" method="post">
<label for="textarea">Title:</label>
<p></p>
<textarea rows="1" cols="100" name="title"></textarea>
<br></br>
<label for="textarea">Author:</label>
<p></p>
<textarea rows="1" cols="100" name="author"></textarea>
<br></br>
<label for="textarea">Description:</label>
<p></p>
<textarea rows="15" cols="100" name="desc"></textarea>
<br></br>
<label for="textarea">Body:</label>
<p></p>
<textarea rows="15" cols="100" name="body"></textarea>
<br></br>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
</body>
</html>
That information gets sent to foo.php, and I would like foo.php to dynamically create a div with the title, author, publish date, and description displayed within. This div would then have a "Read More" button that would display the actual article or "body" in this case.
I would then like to insert this div into a seperate html page. So in other words, every time the user creating a new article clicks the submit button, the information is processed, added to a div element and then that div is inserted into another html page.
Is there any way to do this, or some sample news/articles tutorial that explains how to do this? I've been searching for hours and there seems to be nothing on this particular topic. I've also tried something along the lines of this, but this has gotten me nowhere, and after 3+ days of trying to figure this out, Im ready to gouge my eyes out.
<script>
<?php
foreach (glob("*.txt") as $filename)
{
$lines_array = file($filename);
$search_string_title = "Article_title";
$search_string_published = "Published";
$search_string_author = "Author";
$search_string_desc = "Description";
$search_string_body = "Body";
foreach($lines_array as $line)
{
if(strpos($line, $search_string_title) !== false)
{
list(,$title_str) = explode(":", $line);
}
if(strpos($line, $search_string_published) !== false)
{
list(,$published_str) = explode(":", $line);
}
if(strpos($line, $search_string_author) !== false)
{
list(,$author_str) = explode(":", $line);
}
if(strpos($line, $search_string_desc) !== false)
{
list(,$desc_str) = explode(":", $line);
}
if(strpos($line, $search_string_body) !== false)
{
list(,$body_str) = explode(":", $line);
}
}
$article_title = $title_str;
$published = $published_str;
$author = $author_str;
$desc = $desc_str;
$body = $body_str;
$news_content= array($article_title, $published, $author, $desc, $body);
}
?>
var news = <?php echo json_encode($news_content) ?>;
var title = news[0];
var published = news[1];
var author = news[2];
var desc = news[3];
var body = news[4];
var div = document.createElement("div");
div.style.width = "600px";
div.style.height = "600px";
div.style.background = "red";
div.style.color = "white";
var sHTML = '<div style="text-align:center; padding:15px; font-weight:bold;">' + title + "<br />" + "<br />" + "Published: " + published + "<br />" + "Author: " + author + "<br />" + "<br />" + desc + </div>';
div.innerHTML = sHTML;
div1.appendChild(div);
</script>