Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 3 of 3

This is a discussion on pre fill form best method? in the Shared & Semi-Dedicated forum
Hi all, I'm new to PHP and am building a PHP/HTML form on a page for users to enter data into a MySQL db. I've ...

  1. #1
    JPC Member
    Join Date
    Apr 2003
    Posts
    16

    pre fill form best method?

    Hi all,

    I'm new to PHP and am building a PHP/HTML form on a page for users to enter data into a MySQL db. I've got everything working and, as they say, have learned a lot of lessons (made mistakes) along the way.

    My question regarding this form is more about style/methods of coding:
    Currently, if users want to edit data existing in a record, they (for example) click a link to "edit record 1". This will take them to the form and php prefills the form with the data from record 1. If users are entering new data, the same form is presented blank.

    At first I split up the form HTML with a lot of little php code snippets to set (prefill) the form element values.

    Then I got the idea of generating the form and writing some JS to fill in the form values. I don't like this idea b/c of the extra code created - the final page source code is longer than needed.

    So I am back to my first idea but I don't like it b/c of all the intermingling of php and html. I don't think it is elegant and it won't be as easy changing the HTML if I could get more separation.

    Any thoughts on a better way?

    Many thanks!

  2. #2
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    The better way is to have HTML templates with so-called escape sequences that are substituted with the actual data.

    PHP script would read these templates and substitute any occurence of '[name]' with the data in the name field of the database, for example and so one with all other fields.
    That would keep a programming part separated from the design part, but I realize that it is a bit tricky for a beginner.
    You may also check a sourceforge.net for some free libraries. For example, formitable is almost exactly what you need, but keep in mind that it is not secure: http://sourceforge.net/projects/formitable/
    So, do not use it for storing CC data, but for a small survey it's just great

  3. #3
    JPC Member
    Join Date
    Apr 2003
    Posts
    16
    Gerilya,

    Thanks! Yes, I just found the replace functions ( str_replace() ) you mentioned - yes, these are what I was hoping existed but didn't think did...

    Not sure if this'll be a 100% solution for what I want but you've given me the roadmap so now I can follow it and see where it takes me.

    I've done a lot with JavaScript and other scripting in the past - the more I learn about PHP the more I love it!
    Last edited by zandermander; 12-04-2003 at 08:08 PM.

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
  •