Page 1 of 1

Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 9:29 am
by redcat48
Hello,

PHP header code is working as it should:

1. After typing comments in the "Comment" box to the right of the video and one clicks the "SUBMIT" button, it sends their comments to the editor.
2. However, the comments need to be retained in the original box for client's page when they return for subsequent revisions.

Here's the page link:
http://www.achallenger.com/ContactForm1 ... d_Page.php

I've also attached a .zip file of the coder for the page.

Thank you for your time and assistance.

Greg

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 10:54 am
by social_experiment
redcat48 wrote:However, the comments need to be retained in the original box for client's page when they return for subsequent revisions.
Are the comments somehow stored in a database? If so you can set a cookie that contains some information linking the post to the user (maybe post id), then when the user accesses the page again, this value is checked and the appropriate comment is placed in the textarea.

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 11:01 am
by brothaofdes
Use $_POST data to put the comments back into the original box. After the form is submitted, you can get the value by looking at the $_POST array.

I put this at the top of EVERY php page I develop so that I can see what is being passed back and forth:

Code: Select all

        // the $dodebug element controls what dev information to display
        $dodebug=1;
        if($dodebug > 0)
        {
            ini_set ("display_errors", "1");
            //error_reporting(E_ALL);
            error_reporting(-1);
            echo "<pre>";
            switch($dodebug)
            {
                case 1:
                    echo "--> Form data (POST) <-- <br>";
                    print_r ($_POST);
                    echo "--> Form data (GET) <-- <br>";
                    print_r ($_GET);
                    echo "--> Header List <-- <br>";
                    //var_dump(headers_list());
                    print_r(headers_list());
                    break;
                case 2:
                    echo "--> Form data (POST) <-- <br>";
                    print_r ($_POST);
                    echo "--> Form data (GET) <-- <br>";
                    print_r ($_GET);
                    echo "--> Form data (SESSION) <-- <br>";
                    print_r ($_SESSION);
                    break;
                case 3:
                    echo "--> Form data (POST) <-- <br>";
                    print_r ($_POST);
                    echo "--> Form data (GET) <-- <br>";
                    print_r ($_GET);
                    echo "--> Form data (SESSION) <-- <br>";
                    print_r ($_SESSION);
                    echo "--> Form data (SERVER) <-- <br>";
                    print_r ($_SERVER);
                    break;
                case 4:
                    echo "--> PHP Info <-- <br>";
                    phpinfo();
                default: 
                    echo "--> Form data (POST) <-- <br>";
                    print_r ($_POST);
                    break;
            }
            echo "</pre>";
        }
        else
        {
            ini_set ("display_errors", "0");
            error_reporting(0);
        }

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 11:15 am
by social_experiment
redcat48 wrote:they return for subsequent revisions.
If the client is leaving the page then returning using $_POST will be useless , if no information is sent, nothing can be displayed.

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 11:28 am
by brothaofdes
1. After typing comments in the "Comment" box to the right of the video and one clicks the "SUBMIT" button, it sends their comments to the editor.
2. However, the comments need to be retained in the original box for client's page when they return for subsequent revisions.
This looks to be a valid option for using $_POST. It never clearly states that the user leaves the editor or viewer pages. My comments were for easily passing data back and forth easily between pages. If they are maintaining a common session, then creating a $_SESSION variable will do the trick.

Obviously if the user leaves the site and returns, this is all moot. And there is no other real way to store the data other than using database (common LAMP technology) anyways. The question was not clear and I posted on how I interpreted it, as did you.

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 11:33 am
by social_experiment
brothaofdes wrote:Obviously if the user leaves the site and returns, this is all moot. And there is no other real way to store the data other than using database (common LAMP technology) anyways. The question was not clear and I posted on how I interpreted it, as did you.
Yes, my observation is based on my interpretation of the question. I did not challenge your point, merely offered another point of interest :)

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 11:56 am
by brothaofdes
Confirmed, and noted. The question was vague, but I think the OP gets the point about there being various ways to handle the problem at hand, and that those solutions are dependent on user usage.

If the OP has more questions, please post some code for review.

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 12:51 pm
by redcat48
Gentlemen,

Yes, the comments must remain in the "comment box" during session and WHEN client comes back.

Is the definitive answer (and only answer is to add a database and capture the comments?

Sorry of the confusion I caused...should have stated both not just one scenario.

Again, thanks for taking your time.

If one could answer this post, I would appreciate it very much.

Greg

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 12:56 pm
by brothaofdes
No problem redcat48, sometimes when trying to explain an issue you want to be brief AND concise. Hard to do especially when dealing with technical issues.

In regard to your dilemma, you need to use both the php inherent arrays AND the database solution. Use the php arrays ($_SESSION and $_POST) while the user is navigating back and forth between pages. Remember that $_POST is only good for a single jump unless you store the values in $_SESSION variables.

Now, when a user comes and goes, the data must be retained somehow. The how is your problem to solve. If you have a database, then the solution is easy. If not, it gets a little (lot) harder.

A database driven site is the only way to go. Easy to manage and flexible.

I hope this helps.

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 1:12 pm
by redcat48
Thanks brothaofdes!

I'll setup a database and try to work through the ($_SESSION and $_POST). I'm a designer and my PHP experience is similar to a kid in high school reading a PHP book.

Again, thanks to everyone who answered my "cries" for help.

Greg

Re: Retaining Comments in Textarea Box after submit.

Posted: Thu Jan 20, 2011 1:59 pm
by brothaofdes
Dude, we have all been there. I started with 1 sample hello world script and now am building content management systems. All self taught. you learn by building, breaking, and fixing. The breaking and fixing is the best way to get this stuff down.