Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End “Post a comment” box, what is it…?

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #31801
    Ethan27
    Member

    Hi guys

    On many blogs, where you type a response, comment etc, I was wondering, are these boxes just HTML textfields with something like PHP attached to them…?

    If so, how would the php part be coded. Would it start with an if statement that would write assist something in writing it to the database then echo out the HTML again once a post has been posted…?.

    I could look at wpress files but am not sure which one does this job.

    Sorry to be so vague its just I am learning PHP and have never thought about it….

    #57907
    jacorre
    Participant

    If you want to look at WordPress files, take a look at the comments.php template file. That is what is responsible for displaying the form as well as the comments.

    #57889
    Ethan27
    Member

    Thanks man

    Just looked at the wp file and now even more confused lol.

    Can anyone make it a bit clearer….???

    #54931
    guiniveretoo
    Member

    Usually, yes, php or some other type of server-side code is responsible for processing a form and creating some sort of response, depending on what you want that form to do. A comment box usually will require code that cleans up the entry (and makes sure that what’s been entered isn’t going to break your website or erase your database) and possibly validates an email address or website if it’s been entered.

    How it works…. Well, if you look at the HTML for a form (‘View Source’ on this page even), in the opening

    tag there will be two values to note: the ‘method’ and ‘action’. The method usually will be ‘post’ or ‘get’, depending on what the form does. “Get” will create a linkable result, so most of the time people use that for search results or any kind of data retrieval. “Post” is a ‘quieter’ method i guess you could say, and is usually used for login forms, comment boxes, or any time you (as the user) need to give information to the website. Okay. The ‘action’ value tells the browser what to do with the form when you press that submit button. Usually it will name a processing script.

    So, say you’re working with a simple comment box, it might look like this:





    The script in “/forums/vanilla/post/comment” will probably have the overall outline something like this:


    if (isset($_POST)) {
    if (isset($_POST)) {
    // process the comment here
    }
    }
    ?>

    The html form will give information to the php script in the form of $_POST – so for each form input you have, there will be a $_POST array key that matches (or $_GET, if that’s the method you’re using). So if you want to make sure that someone entered text into the box, you can tell php:

    … which gives $var a value of ‘false’ if the comment box is empty, and true if it’s not. If you want to have the page print out whatever someone typed in the comment box, then you would type in:

    … wherever you want the text to appear.

    It gets a lot more complicated than this, because most of the time when using a comment box you’re actually adding information to a database. But this is the basics of how it works. Hope it helps!

    #54886
    guiniveretoo
    Member

    PS. Yes, if you’re interested, look up some tutorials to get you started. Once you get the hang of writing basic functions and if… then statements, look at the PHP.net Manual for useful functions: the two I used above are isset() and echo (not technically a function, but whatever). The manual is intimidating to start out, but look at the examples for each function, and check the comments and related functions to help understanding how each one works.

    Good luck!

    #54876
    ccc630
    Member

    You could also use Wufoo if you wanted — it’s basically a plug-and-play form so you don’t have to code everything. Takes a bit of a learning curve, but might get the job done.

    #119639
    ramana0102
    Member

    How to create comment box its showing without refreshing a page?? using PHP without framework… Please help me its urgent coding for me.

    #119642
    TheDoc
    Member

    @ramana0102 – please start your own thread.

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘“Post a comment” box, what is it…?’ is closed to new replies.