Question

I'm redesigning a site that's mainly static content, so a CMS is really not necessary. The only thing that changes is the 'events' page, which my client frequently updates. He does this now by going into the HTML, copying the tags of a previous event, changing whatever needs to be changed and uploading it back to the server. I want to make this easier for him (it's a pain in the a**, as he puts it), but without using a CMS I'm kind of lost.

Is there a way to have a form he can fill in (with place, date, etc.) and then display it on the proper page on submit? I'm thinking it should be possible with PHP but I don't know how to do it.

Était-ce utile?

La solution

DEMO

The cleanest way to do this if you have PHP available is to set up a form that uses PHP to write to a text file, and then subsequent form posts would overwrite the same file. This is a very basic form created with the idea that the user would be the administrator. if this form was user facing to the public you would want toimplement a little more security.

You can format the output in the php script to match the site as needed.

Use this to read in the txt file on the page php file to display the text file:

<?php 
readfile("Post.txt");
?>

HTML Form

<h1>Event Post </h1>
  <form name="blogs" action="eventpost.php" method="post" enctype="multipart/form-data">
    <label for="titlePost">Post Title </label>
    <input type="text" name="titlePost">
    <label for="commentPost">Comment: </label>
    <textarea type="text" name="commentPost" rows="5" cols="35"></textarea>
    <input type="submit" name="submitPost" width="200px" value="Submit"/>
  </form>

PHP Script

<?php
global $output;
$title = $_POST['titlePost'];
$comment = $_POST['commentPost'];
$tagDate = date('l, M d, Y');

$content = "<div><h2>$title</h2><span class=\"dateStamp\"> $tagDate</span><br><br><span>$comment</span>\n</div><hr>\n\r\r";

$file = "Post.txt";

if($_POST['titlePost'] = !"" && $_POST['commentPost'] != ""){

    if (isset($_POST['submitPost'])){
        if (file_put_contents($file, $content) > 0){
                $output = "The post titled <b>$title</b> was accepted. Here is what was posted:<br><br>$comment<hr><br>";
            } else{
                 $output = "<em>Unfortunately ".$title."</em> did not post appropriately.";
            }           
    } else {
        $output = "Your form is not filled out <u>completely.</u>"; 
    }
    echo "<span>".$output."</span>";
}   
?>

Autres conseils

Set it all up like this:

<?
$EventIs = "Event name"
$EventDate = "date"

//etc...
?>

in your HTML:

<p><span class="eventName">Event:  <? echo $EventIs ?></span><br />
<span class="eventDate">Date:  <? echo $EventDate ?></span></p>

That's really oversimplifying it. But it gives you the basic idea. You guy can just edit the variables at the top of the file, and they will appear wherever you want in the code.

If you want these variables set from a post from a form, you will have to save those variables in your database. But that's the basic idea.

From a high level perspective, you could create a form for him to fill out which would, on the back end, store the form contents into a file or database. Then, on the front end, you would read in that file, or database, parse the content, and display it however you like. That's a very common thing to do using PHP.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top