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

How to make a form in php accepting indefinite inputs?

Hi,

New to PHP, I was trying to figure out how to make such a form:

Data: [ ] [add][done]

When I enter a data and click the [add] button, the data gets
added to a list (and preferably the updated list is displayed
on the same page). This repeats until I click [done] button.

Any suggestions, directions?

Thanks,
Ge
Jul 17 '05 #1
6 1693
"Ge B" <ge*@sympatico.ca> wrote in message
news:10**************************@posting.google.c om...
Hi,

New to PHP, I was trying to figure out how to make such a form:

Data: [ ] [add][done]

When I enter a data and click the [add] button, the data gets
added to a list (and preferably the updated list is displayed
on the same page). This repeats until I click [done] button.

Any suggestions, directions?

Thanks,
Ge


You might want to ask this in a Javascript/DHTML group. A server-side only
solution would be very tideous to use.
Jul 17 '05 #2
Ge B wrote:
Hi,

New to PHP, I was trying to figure out how to make such a form:

Data: [ ] [add][done]

When I enter a data and click the [add] button, the data gets
added to a list (and preferably the updated list is displayed
on the same page). This repeats until I click [done] button.

Any suggestions, directions?
yourpage.php:

________________

<?php
if (isset($_POST['action'])) {

// data is entered into database whichever button is pressed

$clean_data = validate_data($_POST['data']);
insert_into_database($clean_data);

if ($_POST['action'] == "done") {

header("Location: http://server/otherpage.php");
exit();
}
}

show_list_of_data_from_database();
?>

<form action="" method="post"> <!-- action="" means this same page -->

<p>
<label for="data">Data:</label><input type="text" name="data" id="data"
value="" />

<input type="submit" name="action" value="add" />
<input type="submit" name="action" value="done" />
</p>
</form>


Thanks,
Ge

Jul 17 '05 #3
Ge
Thanks for the suggestion. I see the point is use database to store
the list. But is there any way that I can store and pass along the list
without going into the database first?

Yes, a portion of the list will eventually go into the database, but at
this stage, I perfer not if I can...

Further suggestions?

Thanks!
Ge

Jul 17 '05 #4
NC
Ge B wrote:

New to PHP, I was trying to figure out how to make such a form:

Data: [ ] [add][done]

When I enter a data and click the [add] button, the data gets
added to a list (and preferably the updated list is displayed
on the same page). This repeats until I click [done] button.

Any suggestions, directions?


Use JavaScript to modify the form on the client side
and submit it to the server when done.

Cheers,
NC

Jul 17 '05 #5
Tom
What about using a SESSION array. For instance,
$_SESSION['valid'][$name]. Thus, to adapt Dani's script above:

if (isset($_POST['action'])) {

// data is entered into database whichever button is pressed

$clean_data = validate_data($_POST['data']);
$_SESSION['valid']['data'] = $clean data ;

if ($_POST['action'] == "done") {

header("Location: http://server/otherpage.php");
exit();
}

Once the user hits done, you'd have the $_SESSION['valid'] array all
ready to drop in the database or do with as you please.
Any obvious drawbacks to that?

Tom

Jul 17 '05 #6

Ge wrote:
Thanks for the suggestion. I see the point is use database to store
the list. But is there any way that I can store and pass along the list without going into the database first?

Yes, a portion of the list will eventually go into the database, but at this stage, I perfer not if I can...


Try this modification of the above code:
<?php
session_start();
$tmp = (isset($_SESSION['tmp']))?$_SESSION['tmp']:array();
if (isset($_POST['action'])) {
// data is added onto the $tmp array whichever button is
pressed
if ($_POST['data'] != '' )$tmp[] =
htmlentities(stripslashes($_POST['data']));
if ($_POST['action'] == "done") {
// clean_data($tmp);
// insert_into_database($tmp);
echo 'The final list of data entered is:<br>'."\n";
for ($i=0;$i<count($tmp);$i++)
echo 'Data: ' . $tmp[$i] . "<br>\n";
unset($_SESSION['tmp']);
exit();
}

$_SESSION['tmp'] = $tmp;

}

for ($i=0;$i<count($tmp);$i++)
echo 'Data: ' . $tmp[$i] . "<br>\n";

?>

<form style="margin-top:0;padding-top:0" action="<? echo
$_SERVER['PHP_SELF'] ?>" method="post">
<label for="data">Data:</label><input type="text" name="data" id="data"
value="" />&nbsp;
<input type="submit" name="action" value="add" />&nbsp;<input
type="submit" name="action" value="done" />
</form>

Ken (posting from Google Groups Beta which unindents code :-( )

Jul 17 '05 #7

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

Similar topics

3
by: cbielich | last post by:
I would like to be able to make a form in access to maximized at all times and under no circumstances can it be minamized. I created the DoCmd.Maximize on load event but it is still possible to...
3
by: Susan Bricker | last post by:
Greetings. I have three forms that are open at the same time. They are related and cascading. The first form (frmEventAdd) is the anchor. Each event can have many Trials. The second form is...
7
by: Dave | last post by:
I have a button on Form1 that hides the form and displays Form2: Form2 myForm2 = new Form2(); myForm2.Show(); this.Hide(); After I do some work in Form2 I want to close it and redisplay...
6
by: Cc | last post by:
hi, how do I make form background colour transparent when I set border style to none?
9
by: Jim Langston | last post by:
This is something I've been thinking about creating, and am trying to get the pieces together. I want to be able to assign values in a method accepting different types. I.E. ...
5
by: Andrew Morton | last post by:
Is it possible to make a form deactivate itself without minimizing it? I have written a small utility which copies selected files from CDs (hundreds of them). I put a CD in the tray and click a...
26
by: Jerim79 | last post by:
I need to create a form that takes a number that the user enters, and duplicates a question the number of times the user entered. For instance, if the customer enters 5 on the first page, when...
3
by: trixxnixon | last post by:
long time no see, what would be the correct addition to the query expression below, so the query would pull all values when the fields on the form are left blank. Between !! And !!
1
Daniel B
by: Daniel B | last post by:
I have tried creating a subform where all the data from the tables is present, therefore the user will have to enter information for a new record into each field. This did not allow me to enter data...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.