SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey folks...I am now working on a CMS for one of my sites.
    Here is a quick example.

    http://www.gravitydigital.com/misc_uploads/updates.html

    I have a good handle on the way it works, but I don't really know how to make it do what I want. I am not that good with forms to begin with. I have been taking apart pieces of other scripts that I have and trying to piece them together. I want it to be nice and easy though.

    Using the example above...I would like to try and do both add and edit in one page (unless it would be better to do it in more pages).

    I am printing out a list of the existing updates (date and id) and putting them in a drop-down list with a Go button. Then I have empty text fields for a new update. If the user selects to edit an existing, the page would reload. The drop down list would disappear and the text areas would be filled with the selected content (pulled out by id).

    If the user chose to enter a new update, then they would fill out the fields and hit submit. The page would reload and show them a preview of the way the update would look. If it was acceptable, then they would press submit again and it would submit to the database.

    I guess what I am asking is for some guidance...

    a) Should I try to make add, edit and preview all on one page? Or would it be easier to use multiple pages?

    b) What is the best way to use the forms? Like I said before, I don't have much experience with forms.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by creole
    a) Should I try to make add, edit and preview all on one page? Or would it be easier to use multiple pages?
    For an experienced PHP coder, the best choice would usually be to implement all of the features you listed in a single page. It would let you reuse things like the form layout between the add and update pages.

    b) What is the best way to use the forms? Like I said before, I don't have much experience with forms.
    Consider the example of a form field for entering a username. If the form is being used to create a new entry, you want the field to appear blank. On the other hand, if the form were being used to edit an entry, you would begin by loading the existing value into a PHP variable, then you'd want the value of that variable to be displayed in the form field.

    The code structure to accomplish this would be something like the following:

    Code:
    <?
    if ($action == "add" or $action == "update") {
      if ($action = "update") {
    
        // Load existing entry from MySQL...
    
        // A sample column...
        $currentUserID = htmlspecialchars($results["UserID"]);
    
        // The form will be submitted as an update
        $formAction = "updateSubmit";
      } else {
        // The form will be submitted as a new entry
        $formAction = "addSubmit";
      }
    
      // The HTML form...
      ?>
      <FORM ACTION="<?=$PHP_SELF?>?action=<?=$formAction?>" METHOD=POST>
        UserID: <INPUT TYPE=TEXT NAME="userid" VALUE="<?=$currentUserID?>">
        ...
      </FORM>
      <?
    }
    ?>
    Notice how if an update is being performed, the $currentUserID variable is assigned a value for display in the form; otherwise, the variable has no value and the form field will appear blank.

    The form submits back to the same document ($PHP_SELF), so you'll also need to check for $action="updateSumbit" and $action="addSubmit" and process the submissions appropriately.

    Hope this helped!
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I always use multiple files for adding and editing but what I do is to split the form used into a separate file e.g. user.frm.php then have user.add.php and user.edit.php and include the user.frm.php into the other two files. I find that this method makes it easier to maintain the all the files.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  4. #4
    SitePoint Zealot Jppr's Avatar
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    creole,

    I'm busy too with a cms, it's almost finished. I use one page admin.php that requires classes.inc to work.
    In classes.inc, there are several classes.

    Table: this class has functions to do simple SQL select, update,insert and delete queries.

    Admin: This is the main part, it has a function update, that automatically checks wether the user wants to add or edit data. It checks if an ID is set, if so -> edit, else add.
    There is a function delete, etc. All the stuff I need is in there.

    Verify: contains functions like verifyEmpty, verifyID, verifyEmail etc. Just simple controle stuff.

    Parse: this has functions convertCID() etc. that takes a category ID, and returns the name of that category by looking it up in the category table.

    If you want to take a look at my cms, or use some code, just mail me at thomasds@gmx.net.

    Cheers,
    Thomas


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
  •