473,386 Members | 1,745 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,386 software developers and data experts.

adding more fields to a form

hi all,

I wonder if I could do the following task in PHP before searching for
javascript which I prefer not to have in my code:

I have a form to create new tables in a database and, since I can't
know how many columns needs each table, I want to load the page with a
single text field in the form and then with a button adding more
fields to the form if required.

so something like this:

text field
"add more fields" button
"submit" button

everytime the "add more fields" button is clicked the page reloads and
the form has another text field to enter the name of the table column.

Can be done with php instead of javascript ?

Thanks in advance for any tip

johnny

Jan 17 '06 #1
5 6492
Johnny, I'm not sure if I understand you correctly, but you can try
this:

note.. I didn't test this code, but I think this is what you're looking
for.

<?PHP

if ($_POST['Submit'])
{
$field = $_POST['field'];

for ($i = 0; $i < count($field); $i++)
{
// echo all results
echo $field[$i] ."<br />\n";
}
}
else
{
// $fc = field count

$fc = $_POST['fc'];
if (!is_numeric($fc) || $fc == "")
{
// if fc isn't set - default it to 1
$fc = 1;
}

if ($_POST['AddField'])
{
// if AddField button was clicked - increment $fc
$fc++;
}
?>
<form action="<?PHP echo $_SERVER['PHP_SELF'];?>" method="post">
<?PHP
for ($i = 1; $i <= $fc; $i++)
{
echo "<input type=\"text\" name=\"field[". $i ."]\"
value=\"\"><br />\n";
}
?>
<input type="submit" name="AddField" value="add more fields">
<input type="submit" name="Submit" value="submit">
<input type="hidden" name="fc" value="<?PHP echo $i;?>">
</form>
<?PHP
}
?>

Jan 17 '06 #2
"johnny" <mr********@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
hi all,

I wonder if I could do the following task in PHP before searching for
javascript which I prefer not to have in my code:

I have a form to create new tables in a database and, since I can't
know how many columns needs each table, I want to load the page with a
single text field in the form and then with a button adding more
fields to the form if required.

so something like this:

text field
"add more fields" button
"submit" button

everytime the "add more fields" button is clicked the page reloads and
the form has another text field to enter the name of the table column.

Can be done with php instead of javascript ?

Thanks in advance for any tip

johnny


Seems pretty straightforward and yes, PHP can handle everything including
validation.

I would simply have a form with a single input and submit button. Every time
an entry is submitted, the page refreshes displaying the same form followed
by the list of previously entered values. The form is always at the top of
the page for convenience. You should also inform the user the table creation
table was successful.
Jan 17 '06 #3
Bosconian wrote:
"johnny" <mr********@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have a form to create new tables in a database and, since I can't
know how many columns needs each table, I want to load the page with a
single text field in the form and then with a button adding more
fields to the form if required.


Seems pretty straightforward and yes, PHP can handle everything including
validation.

I would simply have a form with a single input and submit button. Every time
an entry is submitted, the page refreshes displaying the same form followed
by the list of previously entered values. The form is always at the top of
the page for convenience. You should also inform the user the table creation
table was successful.


Only now did I notice that johnny wants to create tables.

johnny, unless you have a good reason to let users create tables:
Don't do that.
Don't allow users to create tables.
Create all the tables you need before making your script available.

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Jan 17 '06 #4

"Pedro Graca" <he****@dodgeit.com> wrote in message
news:sl*******************@ID-203069.user.individual.net...
Bosconian wrote:
"johnny" <mr********@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have a form to create new tables in a database and, since I can't
know how many columns needs each table, I want to load the page with a
single text field in the form and then with a button adding more
fields to the form if required.


Seems pretty straightforward and yes, PHP can handle everything including validation.

I would simply have a form with a single input and submit button. Every time an entry is submitted, the page refreshes displaying the same form followed by the list of previously entered values. The form is always at the top of the page for convenience. You should also inform the user the table creation table was successful.


Only now did I notice that johnny wants to create tables.

johnny, unless you have a good reason to let users create tables:
Don't do that.
Don't allow users to create tables.
Create all the tables you need before making your script available.

--
If you're posting through Google read <http://cfaj.freeshell.org/google>


I complete agree. I assume this was some sort of admin tool and not for
public consumption.
Jan 17 '06 #5
sorry, I forgot to reply, thanks Adam, this is what I had to do.
For Bosconian and Pedro , yes it's part of an admin tool to create and
manage contact lists, each list has its own table.

johnny

Jan 21 '06 #6

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

Similar topics

1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
11
by: Bobbak | last post by:
Hello All, I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and ‘Stats') that each contain the list of EmployeeIDs, I want to be able to create a Module in which I could call in my VB...
1
by: Tony D. | last post by:
I could really use some help with a problem I am having. I am trying to add a new field to an existing form that combines two tables into one form. In this same databse I have another form that...
2
by: Randy A. Bohannon | last post by:
This is probably a simple thing to do, but I can't find how in the help files or the manual I have. I'm using Access 2000. I have three tables joined by a common field, and I'm using one form...
1
by: RC | last post by:
I have an Access 2002 database with many tables and forms (but just to keep things simple, let's say the DB has one Table "Table1" and one Form "Form1"). I have managed to cobble together so much...
2
by: brenda.stow | last post by:
error msg " An error occured while referencing the object. You tried to run a visual basic procedure that improperly references a property or method of an object" This msg occurs everytime I add a...
5
by: sara | last post by:
Hi - I have 2 new questions in a new database I'm trying to develop. The first has 6 fields on a table and allows the user to enter them on a form. The form is bound to the table. All 6...
1
by: vivekvt | last post by:
-------------------------------------------------------------------------------- here is the code to the asp page that adds data to the access database! <html> <body> <% Dim recordsaffected
18
omerbutt
by: omerbutt | last post by:
AJAX PROB WITH MULTIPLE RECORDS helo iam having problem in ma code will any body look out an help, i am trying t add sale record in the database and the checkthe quantity of the part slod and...
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: 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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.