473,748 Members | 7,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple forms within a Switch statement

Ok... I have to make this administation area where I have multiple Contents
to add edit delete publish .
The problem is that I don't know what is the best way of making the forms.
At the moment I create a new PHP file for add_page.php, add_student.php ,
add_news.php, edit_page.php list_page.php and so on.

This way doesn't seem very good to me and I am wondering if I want to put
them in one file or in some more generic files, how am I going to do that.

For start created the content.php and did a switch $_GET['category'] and a
nested $_GET['action'] but I don't know what each case: should contain.

I don't want to put the whole html code for the forms in each case....
I have tried puting each form in a function but I had some stupid errors and
that also doesn't sound to me a good solution.

So if someone has previous experience pls Suggest me something...

Jul 17 '05 #1
4 2400
To be honest, using a switch for this kind of thing starts off looking
good, but turns into a maintenance nightmare. Also, you want to avoid
pages with modes. Think of your pages much the same way you think of
functions. Each page has a specific purpose: Gather sudent data from
the user, validate / insert student data into the DB, delete a student,
etc.

Your first method isn't that bad, to be honest. I would change the
names a little bit, so that they group together in a directory listing:

news-add.php
news-delete.php
news-update.php
student-add.php
student-delete.php
student-edit.php
student-insert.php

Need to make a change to the form to add a student? The code you're
looking for becomes easy to find.

(repeats mantra) Simple is good... simple is good...

Jul 17 '05 #2
*** Angelos wrote/escribió (Tue, 17 May 2005 12:59:09 +0000 (UTC)):
The problem is that I don't know what is the best way of making the forms.
At the moment I create a new PHP file for add_page.php, add_student.php ,
add_news.php, edit_page.php list_page.php and so on.


Keep it simple.

Keep it simple unless you're building a huge site like "Amazon.com ". Your
approach looks good to me. It'd only change it if I were duplicating code,
and in the latter case you might solve it moving code to common
classes/functions.
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #3
Ok thanks to Both of you (dracolytch and alvaro) for your suggestions.
I have just managed to make it by having a content.php with just the switch
statements and each case: in it calling the appropriate Function from a
form_functions. php file.

I am not really sure what is the best ... but I'll try it both ways !!!
Thanks again I ma still open to other Suggestions !
Jul 17 '05 #4
"Angelos" <an*****@redcat media.net> wrote:
Ok... I have to make this administation area where I have multiple Contents
to add edit delete publish .
The problem is that I don't know what is the best way of making the forms.
At the moment I create a new PHP file for add_page.php, add_student.php ,
add_news.php, edit_page.php list_page.php and so on.

This way doesn't seem very good to me and I am wondering if I want to put
them in one file or in some more generic files, how am I going to do that.

For start created the content.php and did a switch $_GET['category'] and a
nested $_GET['action'] but I don't know what each case: should contain.

I don't want to put the whole html code for the forms in each case....
I have tried puting each form in a function but I had some stupid errors and
that also doesn't sound to me a good solution.

So if someone has previous experience pls Suggest me something...


This is the basic schema I use: every GET/POST request should return
two parameters: the name of a function (func) and the argument of that
function (arg). The argument is serialized and URL-encoded.

<?
function add_page($form)
/* Show the FORM. $form may be null or may be the data to be
modified or to be corrected. */
{
echo "<html><body><h 1>Add page</h1>"
. "<form method=post action=" . $_SERVER['PHP_SELF'] . ">"
. "<input type=hidden name=func value=POST_add_ page>"
. "<input type=hidden name=arg value=>"
. "<input type=text name=field1 value=" . enc_val($form->field1) .">"
#...
. "<input type=text name=fieldn value=" . enc_val($form->fieldn) .">"
. "<input type=submit name=b value=Save>"
. "</form>"
. "</body></html>";
}

function POST_add_page($ arg_not_used)
/* Take the POST request from add_page() */
{
/* Acquire POST into an object: */
$form->field1 = $_POST['field1'];
...
$form->fieldn = $_POST['fieldn'];

/* Validate all the data: */
$err = "";
if( $form->field1 is not valid )
$err .= "Data1 not valid because so and so...";
...
if( $form->field1 is not valid )
$err .= "Data1 not valid because so and so...";

if( strlen($err) == 0 ){
# store data in the DB.
# show next page - for example another empty form:
add_page(null);
} else {
echo "<html><body>In valid: $err<p>"
. "<a href=$_SERVER['PHP_SELF']?func=add_page& arg="
. urlencode( serialize( $form ) ) . "RETRY</a>"
. "</body></html>";
}
}

/* More functions here. */
/* Request handler: */
$func = $_REQUEST['func'];
$arg = $_REQUEST['arg'];
if( strlen($arg) == 0 )
$arg = null;
else
$arg = unserialize($ar g);
switch( $func ){
case 'add_page': add_page($arg); break;
case 'POST_add_page' : POST_add_page($ arg); break;
# more functions here.
default: something_maybe _add_page($arg) ;
}

?>
All the code may be semplified if you implement these functions;

function Form($func, $arg)
# Open the form that send the POST to the function $func with
# argument $arg; set the hidden fields accordingly.

function Anchor($text, $func, $arg)
# Print an anchor to call the function $func with argument $arg
# and clickable text $text.

As an evolution of these concepts, you may allow two or more buttons in
each form, associating each button to a different function/argument of
the module. This is coerent with the concept that every "click" on your
WEB application may call a different, specific function:

function Button($text, $func, $arg)

The correctness of the parameters returned by the client may be ensured
adding a MAC (message authentication code) computed over the $func and
the $arg variables. This MAC is generated by the functions Anchor() and
Button() and must be checked by the "request handler" on every request.

Another and even more interesting feature to explore is the introduction
of a stack of $func/$arg values, so to implement the "return" instruction
commonly available on every programming language. The availability of
a stack open the way to the modularization of the WEB applications.

Ciao,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

Jul 17 '05 #5

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

Similar topics

2
2534
by: Angelos | last post by:
Ok... I have to make this administation area where I have multiple Contents to add edit delete publish . The problem is that I don't know what is the best way of making the forms. At the moment I create a new PHP file for add_page.php, add_student.php, add_news.php, edit_page.php list_page.php and so on. This way doesn't seem very good to me and I am wondering if I want to put them in one file or in some more generic files, how am I...
8
5520
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE, UPDATE, DELETE) which are controlled by a web frontend and the table records are manipulated to control the permissions. Example: The Press Release section record would look like this: Username: John Doe Function Name: Press Release
4
21104
by: ShyGuy | last post by:
I have a table with 4 fields. Three are used for criteria. I can get the DLookup to work with 1 criteria with the following but can't get it to work with 2 or three. NumofAppts = DLookup("", "LookUpAppts", " = " & Forms!!NumofPeople) Can someone tell me how to add multiple criteria? I tried "And" but it doesn't seem to work.
11
4532
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my database,just help in getting me pointed in the right direction. I have a database with 8 tables, which from what I have read, cannot be linked on a single form, and be updatable. I have created a query which includes all 8 tables, and then...
0
1980
by: jon | last post by:
Using Visual C++ and MFC, one could generate a very nice MMI using CFormView and the method detailed in the MSDN "vswap" example to allow multiple forms to be viewed ( switched to ) within a single application ( i.e. a single app running and a single window). A very useful method indeed - very rapid to develop, forms designed at design time, all forms encapsulated within one window, SDI, only one task on taskbar etc... Now, i know...
2
20364
by: Guadala Harry | last post by:
After RTFM, I hope I have missed something: I would like to have a switch() statement process multiple input values the same way - but without having multiple case: blocks for multiple input values that need to be processed the same way. For example, please consider the following sample switch block and notice that "other value 1, 2, and 3" all execute DoOtherThing(). How can I get all of those cases to NOT have to appear in their own...
13
8348
by: jsta43catrocks | last post by:
In C++, my "switch" statement is okay when I ask it do evaluate ONE expression. (My number that I'm evaluating is one of ten single digits; I have ten cases for the ten digits.) BUT, I have five separate digits to evaluate. I can't believe that the only solution is to do: switch (num1) { case 0:... case 9:
16
12939
by: Silent1Mezzo | last post by:
Is it possible to have multiple control variables in a switch statement? For example: switch(a , b) { case(a>b): case(b<a): case(a==b): }
3
2606
by: Major Doug | last post by:
Hello: situation--I have a research database. Each record in the database consists of 10 fields. I used access97 to rack/stack my database; very easy in the beginning. I created a form with a combobox. Using some information I found through this forum, I created the comboxbox in the form's header linked to textboxes in the form's detail. I could click on the column and see the linked data populate the 10 textboxes. I could easily maneuver...
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.