473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

suggestions wanted concerning form handling "template"

OK, I am devising a php page that will handle a form submission, and
wanted to know if anyone has already setup such an idea, or if you had
links to point to good tutorials on this.

Basically I have a form (which I use smarty templating to display, and
smartyvalidator to validate).

The php page basically is driven by the action variable (add,
add_confirm, edit, edit_confirm, view, delete). When the form starts
out, it is in view mode. Then if you click the add button, it switches
to add mode. Confirming a new addition sends you into add_confirm
(which would write to a DB, etc.). Edit would work the same way, except
edit mode would lookup a record to display, edit_confirm would update
that record, delete mode would delete, and view mode would basically
display data (to edit/add/delete).

Sounds easy, but my code is pretty long and I am looking to simplify
this idea. Looking for how you all do this, and if anyone has a
"template" setup to do this.

Mine would be something like:

if ($action == "view") {
// do something

..... etc ....

Ideas? Let me know. Thanks,
Jim

Jul 17 '05 #1
6 1697
DJ Majestik wrote:
OK, I am devising a php page that will handle a form submission, and
wanted to know if anyone has already setup such an idea, or if you had
links to point to good tutorials on this.

Basically I have a form (which I use smarty templating to display, and
smartyvalidator to validate).

The php page basically is driven by the action variable (add,
add_confirm, edit, edit_confirm, view, delete). When the form starts
out, it is in view mode. Then if you click the add button, it switches
to add mode. Confirming a new addition sends you into add_confirm
(which would write to a DB, etc.). Edit would work the same way, except
edit mode would lookup a record to display, edit_confirm would update
that record, delete mode would delete, and view mode would basically
display data (to edit/add/delete).

Sounds easy, but my code is pretty long and I am looking to simplify
this idea. Looking for how you all do this, and if anyone has a
"template" setup to do this.

Mine would be something like:

if ($action == "view") {
// do something

.... etc ....

Ideas? Let me know. Thanks,
Jim


I don't know what you mean by "long", but our body of code that does this
is:

1) The HTML file at 332 lines
2) The processing file at 155 lines
3) About 200 lines of code in our main library

Each table also has a separate file that defines all of its parameters, but
these are computer-generated so we don't really think about length.

So anyway, your basic approach seems sound, but I'll warn you of one thing
we ran into. We allow two states, a browse of search results, and a
one-row detail view. This complicates the code a bit.

We've done away with the switch-to-edit-mode, it is not really necessary.
When a user views a row, they can save or not save, they are always in edit
mode.

We've done away with fancy client-side javascript control of the page and do
lots of round trips to the server. Here is one reason. If the user is
editing a row, then the column "state" might be a drop-down list of US
States. But if the user is in "search" mode, then you want free-form entry
there.

Hope this helps, we have done a complete version of this so I'd be happy to
answer any questions I can.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #2
Definitely helps, thanks! These are all things I hadn't thought about.
If anyone has any other ideas, they are definitely helping in
"solidifying" my code.

I want to basically write a template, then use that for other forms
(modifying stuff like DB, etc.) but the flow would remain the same.

Thanks again,
JJ

Jul 17 '05 #3
DJ Majestik wrote:
Definitely helps, thanks! These are all things I hadn't thought about.
If anyone has any other ideas, they are definitely helping in
"solidifying" my code.

I want to basically write a template, then use that for other forms
(modifying stuff like DB, etc.) but the flow would remain the same.

Thanks again,
JJ


Concerning templates, there are two schools of thought there, at least.

School one is the one-file-per-table method. Here the programmer codes up
the HTML and other stuff on a table-by-table method. Sounds easy at first
because one page goes fast, but it bogs down really fast when the system
grows. The advantage of OO here is illusory, you can do just as well with
wrappers. But whether you use OO or wrappers the unavoidable fact is that
there *must* be a file for each table, and that determines how the rest of
your life will go with this project.

School two, of which I am a humble member, is the library+data method. You
have a single library of generic code, and the only difference from table
to table is a body of meta-data that describes each table. The library
does HTML generation, formulates SELECT and INSERT statements and so forth.

My own opinion is that there is no real advantage to School One at all, it
appears that you can get working code faster, but it turns out to be an
illusion. The actual speed to *production* code is faster with School two,
because there is far less code to write. The real reason most people avoid
School Two is that it requires you to think a little bit before you code.

Another advantage of school two is that it is very flexible about when to
generate code. You can use the library to grind out a bunch of HTML
fragments for each table, or you can run them out on demand for each table
access, but you use the same code in both cases.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #4
Ken,

You and I are on the same wavelengths. I am actually utilizing your
"school 2" ideology presently in my coding. I think that OO would be
nice, but in a PHP 4 world, I think it makes more sense to use
libraries. I have basic common functionality broken out that does all
teh DB stuff, validation stuff, etc.

So that is exactly what I am doing. Do you use my idea of "actions" to
drive what you do in the PHP code.

As an aside, I use Smarty templating for the HTML, and PEAR for the DB
abstraction, etc. I am just trying to simplify the process.

So it appears that I am on the right track.

Thanks,
JJ

Jul 17 '05 #5
DJ Majestik wrote:
Ken,

You and I are on the same wavelengths. I am actually utilizing your
"school 2" ideology presently in my coding. I think that OO would be
nice, but in a PHP 4 world, I think it makes more sense to use
libraries. I have basic common functionality broken out that does all
teh DB stuff, validation stuff, etc.

So that is exactly what I am doing. Do you use my idea of "actions" to
drive what you do in the PHP code.

Yes, this is our code for that:

switch ($this->gp_action) {
case "":
SessionSet("tables_".$this->table_id."_search",array());
case "searchexecute":
break;
case "savesearch":
SessionSet("tables_".$this->table_id."_search",CleanBoxes(true));
break;
case "del":
TABLE_DELETE($this->table_id);
if (Errors()) {
$this->gp_action="edit";
$this->display="boxes";
}
break;
case "print":
$this->display="print";
break;
case "save":
TABLE_SAVE($this->table_id);
$this->TriggersSaveAfter();
$this->gp_action = "edit";
case "edit":
case "search":
case "ins":
$this->display = "boxes";
}
As an aside, I use Smarty templating for the HTML, and PEAR for the DB
abstraction, etc. I am just trying to simplify the process.
I tend to avoid Smarty, seems to me a lot of work. Why tell Smarty that you
are using a variable called $MyValue and then put {MyValue} into a form
when I can just put <?=$MyValue?> into the form?

Pear DB looks really good. Have not put it in yet, since we wrapped
everything in our own routines anyway.

So it appears that I am on the right track.

Thanks,
JJ


--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #6
Nice code, looks like a lot of what I am doing (different routines,
same idea). Smarty is good in my environment because it allows design
abstraction, i.e. I have the designer do all that work, I make
available certain variables that I want him to have and do all the work
in the back end (hence the "template" scheme I am trying to revise).

Thanks for posting your code, all this has really helped in my flow.

Take care,
JJ

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gianni Mariani | last post by:
I remember seeing a neat template specialization trick posted here a few months ago that allowed the detection of a type containing a member. After a day searching through google archives I come up...
10
by: Lionel B | last post by:
Greetings, I cannot figure out why the following code does not compile: --- BEGIN CODE --- typedef double ftype(double); struct A {
1
by: Perttu Pulkkinen | last post by:
I would like to have a javasript/jscript function template/"framwork" instead of checking browsers by name. The shortness of script in my opinion is not the goal, but clearness and ease iof...
5
by: Jacky Yuk | last post by:
Hi all, I am new to c++ but using c for long time. Recently, I created a MFC GUI project by VC/C++ 6.0. Everything was fine until I wanted to use "template": template <typename T> class...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
2
by: Brent | last post by:
Like many sites, mine has a standard "look" -- a template, if you will -- that visitors see on each page. I've tried to keep the code and HTML separate to the extent possible, and for most standard...
9
by: Kobe | last post by:
Is there any difference in: template <class T> vs. template <typename T> ?
0
by: Robbie Hatley | last post by:
I'd always thougth that a C++ compiler/linker should be able to instantiate a template in mulitple places (say, in two different translation units), even using the same template parameters so that...
2
by: Robbie Hatley | last post by:
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote: > Robbie Hatley wrote: > > > > I ran into a problem a few days ago when I added a couple of > > template functions to one of my personal...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.