SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,531
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Need help with Reviewing/Editing a Comments Form

    I just added the ability for Users to add Comments to articles on my website.

    However, it occurred to me today on my way to supper that I haven't given Users the ability to "preview" or "edit" their Comments before they are submitted for good?!

    I am not really sure how to go from my Comments Form to re-displaying the User's Comments to allow previewing and editing?!

    For instance, where do I store things going from the Form to the Preview?

    Do I store the Comments in $_SESSION?

    Do I store the Comments in my Database?

    Something else?

    I could use some help and direction on how to tackle this!!

    Hopefully it won't be too hard to add this extra functionality on to my Comments Form?!


    Debbie

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    2 Thread(s)
    Hi Debbie,

    Others will have differing views on this and will say to store it in sessions, or do it this way or that way...

    Personally, I would serialze the form data and write it to the database. Then I would pull it from the database using AJAX that calls a php script that returns a preview of this data. I would store in the Session the Id of the serialized data in your table so that you know what serialized record to get, and then I would use AJAX again to post this data to a php script that writes it too the database.

    Using this method the user will never leave the page and can preview and commit (or cancel) too.

    Regards,
    Steve
    ictus==""

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,531
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Hi Debbie,

    Others will have differing views on this and will say to store it in sessions, or do it this way or that way...

    Personally, I would serialze the form data and write it to the database. Then I would pull it from the database using AJAX that calls a php script that returns a preview of this data. I would store in the Session the Id of the serialized data in your table so that you know what serialized record to get, and then I would use AJAX again to post this data to a php script that writes it too the database.

    Using this method the user will never leave the page and can preview and commit (or cancel) too.

    Regards,
    Steve
    Thanks for the suggestion, but I'm not ready for AJAX yet?!

    So, with that option out, what would be a more "plain-vanilla" approach?

    If the User is on the "Add a Comment" form on my Article page, then it would seem easiest to do this...

    - Display the Comments Form
    - Have a "Submit" button
    - Have a "Preview" button
    - If the User clicks "Submit", then write it to the Database
    - If the User clicks "Preview", then store the data in $_SESSION
    - Display a "Preview" page with the User's Comments shown how they will look when they are submitted, and display the "Add a Comment" form below this with the Form pre-populated with data from the $_SESSION.


    Debbie

  4. #4
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    2 Thread(s)
    Hi Debbie,

    Your way will work. You could skip the overhead of the database and sessions stuff by doing something like:
    PHP Code:
    <?php
    if(isset(htmlentities($_POST['preview'])){
      /Do 
    preview php code here
    }
    if(isset(
    htmlentities($_POST['submit'])){
      /Do 
    submit php code here
    }
    ?>
    <form method='POST' action='my_form.php'>
     <input type='text' name='info'>
     <input name='submit' type='submit' value='submit'>
     <input name='preview' type='submit' value='preview'>
    </form>
    Regards,
    Steve
    ictus==""

  5. #5
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,531
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Hi Debbie,

    Your way will work. You could skip the overhead of the database and sessions stuff by doing something like:
    PHP Code:
    <?php
    if(isset(htmlentities($_POST['preview'])){
      /Do 
    preview php code here
    }
    if(isset(
    htmlentities($_POST['submit'])){
      /Do 
    submit php code here
    }
    ?>
    <form method='POST' action='my_form.php'>
     <input type='text' name='info'>
     <input name='submit' type='submit' value='submit'>
     <input name='preview' type='submit' value='preview'>
    </form>
    Regards,
    Steve
    Good suggestion. That is what I am playing with now.

    Thanks,


    Debbie


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •