Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Dynamic Form - How To Set Values Of A List


I have a form with a list/menu in it that is populated with records from a database. The items in list#2 are based upon what is selected in list#1.

I have been able to use a combination of php and javascript to get it to work, but the javascript reloads the page to get list #2 to refresh - and that clears out any other fields that have been filled in. Instead of javascript being called for the 'onchange' event for list #1, I'd rather it call php when list#1 is changed and so reset the values in list#2.

OPTIONS:
1. I thought I could have a php function that is called (i.e.   onchange="<?php reload();?>" but I can't figure out how to set the values of the list from within the php function. How to reference form objects with php?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Dynamic Form Option List
I want to create a dynamic drop down option list in a form, but I just can't wrap my head around this.

Both of the below scripts work as intended, but how do I make the mySql query results work with my existing script?  Yes, I know I must replace the "$options = array" part in the top piece of code, but I need a little more guidance than that. Code:

Retrieve Array From FORM List Of Values?
I have created a form where a user selects 2 items from a list of 8 values.
That form field is called "choices" and returns a value to the php file as
$choices. This form posed no problem when I only allowed a single item to be
selected, but the client now needs to have 2 items selected at a time.

The problem I'm having is that I don't know how to turn the multiple
selections on the form in to an array. I thought the $choices variable
would automatically become an array, but
Using[color=blue]
> for ( $i = 0; $i<2; $i++ )
> echo "$choices[$i] ";[/color]
only returns the first two letters of the last selected item value.

And
[color=blue]
> foreach($choices as $articles)
> echo $articles. ' ' ;[/color]

Returns an invalid argument.

While echo $choices returns the second item selected in the list, but not
the first.
It appears that the variable is replacing the first item selected with the
second rather than returning an array.

Posting Form List Multiple Values ?
how to get the values using post from a multiple list form when more than one value is selected ?.. is it possible ?

Comparing User Input Values In A Form With Database Values
I want to compare user input values in a form with my database.
Basically I want to check whether the user exits in my database.
What mysql command can do that?

A Dynamic Drop Down List
I need to create a dynamic drop down list. By this i mean that the webpage html form = select style will recieve all the values as based on a query to a mysql database. I have no problems quering the data base with PHP, But i need to make some kind of for loop that will add a new value to the selct form for each result from the database. my thought process go like this.

1. call data base to guery. (no problem)

2. make variable variables that will be created according to the number of results (these variables must be created according to results of query, not a problem i think)

3. make a form like this

<form action = ***** method = post>
<select name = ******>
<option value = "This is a query result"> This is a query result> //This is the part i need to using a for loop and variable variables
</select></form>

so my problem is part 3, cause is this all done in PHP, or if i had all these variables, can i do this in HTML? Can i make a for loop in PHP that would break into HTML during these parts?

Dynamic Mailing List?
I have a schedule of people that need reminders sent to them weekly.  I have figured out how to set a Crontab to send the reminder automatically ... but the people are not the same every week.  I know that I could build multiple scripts and hard code the email addresses, setting a cron job for each - but is there any way to build ONE script that will read a text file based on the date and pull the names/email addresses off of that? 

Dynamic List Order
I was trying to get the list box to display the id numbers in ascending order however the code below does not work, just wondering how to fix it?

<?php
$g = "SELECT * FROM em ORDER BY iD ASC";
$q = mysql_query($g, $link_id) or die(mysql_error());

if (mysql_num_rows($q) > 0)
{
?>
<select name="d">
<?php
while($r = mysql_fetch_assoc($q))
{
?>
  <option value="<?php echo $r['Id']; ?>"><?php echo $r['Id']; ?></option>
<?php
}
}
?>

Dynamic List Population
how do you populate a list dynamically? for example I have the following in a table but I can't get them into the list after the query is performed.

<form action="">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>

Generating A Dynamic List
I am tying to write a statement that will compare the values of 2 columns, and display the result in a temp table.

ex. Table A has the following columns: "Minimum" and "Maximum." The temp table will hold the reult of the difference between the 2 columns of table A.

Scope: I am trying to crate a drop down with the resulting data as it is incremented. If Min = 2 and Max = 7, the TEMP tab;e should get the results of 2,3,4,5,6,7. I want to have this result displayed in a drop-down list.

Scanning List Of Values
Say I have a list of values in an array:

Data_Field_1
Data_Field_2
Data_Field_3
Data_Field_4
Data_Field_6

How can i pick out that Data_Field_5, is missing out of this list? So Basically I need a formula that takes in a portion of the string (i.e. everything in front of the number) and scans the list of numbers and returns the first number that isn't in sequence. How would i do this?

Dynamic List Items Repeating Themselves
I'm working on this online magazine, and each page (well, other than the front page) has a menu included on the right-hand side consisting of articles divided into three sections: articles, columns, reviews. For some reason, whenever I click on one of these article links, that link takes the place of the first link in the section. You can see what I mean here: PHP for the included right_menu.php PHP Code:

Dynamic Checkbox List - DB Update
I have a set of questions which are being dynamically output:

for($i=0; $i<count($question_array); $i++)
{echo $question_array[$i][question] .

"<input type='checkbox' name='question_" . $question_array[$i][id] . "' value='Y'' . "><br>";}

I then want to update each question in the DB. I want to loop through each question id and carry out the relevant action (either enable or disable). What is the best way to do this?? As I am dynamically generating the variable name (e.g. question_50) what is the best way to loop through these updating the relevant id?

Dynamic Drop-down List In Array
Q. How do I create a dynamically-generated drop-down list for use in
an array.

I'm using PHP with a MySQL database (through phpMyAdmin)

My database table is called com_courses, and I want to pull the
distinct 'title' fields and have them appear as a drop down menu for
the user to select in a form.

Here is my array, with (at the moment) manually-entered 'titles'
(which I now need to be dynamically generated from my database field:
'com_courses.title'

array (
"coursetitle",
"Course Title:",
$EXTRA_SELECTLIST,

array ("Report Writing", "Recruitment & Selection", "Presentation
Skills", "Essential Telephone Skills", "Time Managememt", "Customer
Care", "Other"),
0
),

I am not an experienced programmer, but can play around with php to
customize programs. I've read up on arrays (I bought a "Programming
with PHP and MySQL" book, but it just stops short of this problem). I
can't figure this one out.

The Dynamic Zone Of List PHP. Please It 's Very Urgent!
I want to create in a form in php two zone of list (A and B).
the options of the zone lists B are dependent on the option chosen in
zone A.

Searching Dynamic Driven List
I have a members database will all their personal details in. I have a page running a SQL query to display a complete list of all these people. This is what my query looks like:

$sql_prop = "SELECT * FROM $db.members WHERE area = '".$_REQUEST['area']. "' ORDER BY name ASC;
$result_prop = mysql_query($sql_prop) or die(error_report("Mysql Error", mysql_error()."

$sql_prop", $_SERVER['REMOTE_ADDR']));

"Error Report" is just one of my functions. I have two forms fields on this page, "Name" and "Address". I want to be able to search the listing that this SQL query has returned for those fields, ie. the user enters "John" in the form field and it returns all entries within the query matching "John". The reason I'm using this:

area = '".$_REQUEST['area']. "'
in the WHERE clause, is just to ensure that the person viewing this list can only see members that are in his area. On the previous page there is a piece of code that gets the session "area" and brings it across to this page. I'm keen on keeping that code in. It works for me at the moment.

Any ideas? How can I search this already filtered list?

How Do I Get An Ordered List Of Values To Print?
I have a database of my audio CD collection, and I'm trying to get the song titles of each album to print in an ordered list format. Each album is printed in a new table row.
For some reason a new row is printed for each song title.

Below is part of my script. I included what parts I thought were important. You can see the current output here. The output I want is available here. Notice that the song titles have a number next to them. PHP Code:

Adding Dynamic Values To An Array
I am having a problem adding dynamic values to an array. The values that I want to add to the array are sent via a query string. The array is stored in a session.

the variables are sent like:

?var=test1
?var=test2

How can I send these variables to an array. I tried doing it like this:

$_SESSION['varList'] = '"'.$_SESSION['varList']'",'.$var;

but this only creates one entry in the array which is "test1","test2"

Dynamic List Populated By MySQL Table
I am building my first php page and I've ran into problems trying to create a dynamic drop down list for an INSERT page. My page is based on this example from mysql.com.

I want to populate the list from a table in MySQL, but when I test the page the list only contains the first record. If anyone can help me out, or recommend an easy way to create dynamic menus/lists, I will be very grateful.

This code appears above the FORM ACTION:

$NearMajorCity = mysql_query("SELECT NearMajorCity_ID, NearMajorCity FROM NearMajorCity");

This code is within the FORM:

<SELECT NAME="NearMajorCity" SIZE=1>
<OPTION SELECTED VALUE="">Select One
<OPTION VALUE="">---------
<?php
while ($NearMajorCity = mysql_fetch_array($NearMajorCity)) {
$NearMajorCity_ID = $NearMajorCity["NearMajorCity_ID"];
$NearMajorCity = $NearMajorCity["NearMajorCity"];
echo("<OPTION VALUE='$NearMajorCity_ID'>$NearMajorCity
");
}
?>
</SELECT>

I want to be able to view the names of the Major Cities in the list, but I want the NearMajorCity_ID inserted into the table.

Member Area With Dynamic File List
I have an Apache 1.3.31 with PHP 4.4.1 available and want to create
some kind of "member area" with a per-user or per-group listing of
files that can be downloaded.

How would I do this?

At present I just protect the individual files using .htaccess
and .htpasswd files and give out direct URLs to the files together with
username/password. What I'd like is some login functionality where
people can log in using their username/password and then find a list of
files they can download together with additional information
individually tailored for that user.

Dynamic Drop-down List With Array - Question
Can anyone out there give me a pointer regarding creating a
dynamically-generated drop-down list connected to an array?

And is that question as clear as chocolate spread?

Here's what I've got. I'm using PHP and MySQL database. I'm customizing
some calendar software, and I want the user to fill in a form by
selecting a title from a drop-down list, generated by my MySQL
database. However, the program I'm customizing uses arrays, which is
where I'm stumped.

What do I need to add to this code to make the array of titles(eg
"report writing" etc) come from my database, rather than the
manually-entered values that you can see here.

The field I want to pull from is called com_courses.title

array (
"coursetitle",
"Course Title:",
$EXTRA_SELECTLIST,

array ("Report Writing", "Recruitment & Selection", "Presentation
Skills", "Essential Telephone Skills", "Time Managememt", "Customer
Care", "Other"),
0
),

I hope it's not cheeky to ask this,
BTW I bought a book on Programming with PHP and MySQL, but it doesn't
answer this question,

Detect Duplicate Values In A Ranked List
Spreadsheets like Excel do a nice job of detecting if there are duplicate values with their rank function - this is what I would like to mimic. This is my small script that detects the rank position of a variable Hank_Wins in a mysql database: PHP Code:

Combo/list Box Showing Values Selected
I have a combo box being populated dynamically through php using a mysql database, and everything works fine.

My question is: How would i make it keep the values selected, once the user hits the submit button? For example, let's say i have a combo box with the values 1 2 3 4 5 in it. The user selects &#393;' and hits the submit button (which posts to the same page). At that point, i'd like the combo box to still have &#393;' selected, instead of resetting itself.

Popup Window List Of Values To Select
What i need to do is bring up a popup window with a list of values(values looked up from the database). The user should be able to select one of the values from the list and the value then populate a text box on the calling form.

Add Form Field Values Into Php Seesion Variable Before Submitting The Form
I have php page which is basically a simple html form containing some text fields.The user will type in values in it and submit it .Now what i want is that just at the time of submittion i want to assign the form field values in session variables.

I nwwd this b'coz the form is being submitted into a cgi script which has been given to me.Now the cgi script is an executable one and i am unable to view or change its content,Its functionability is to change a password for a linux user account .Now the cgi script after completing the job is redirected to another html page.What i have to do is that i need to trap the user input and update the values in a mysql database .Now if i can assign the values in a session variable then i can do the updatation from some later pages.

Dynamic Form Fields/multiple Page Form?
It is for a friends out of print booksite, where visitors can request multiple books to be searched by adding one at a time to a cart (javascript), then once all added they submit to another form where they enter their personal details and all is sent through. The problem is at the moment they cannot change whats in the cart without refreshing the browser window and losing everything.

1) present for asking how many books they want to search for
2) display multiple rows of the same input fields depending on how many books they say they want to have searched for?i.e

title|author|publisher|etc
title|author|publisher|etc
title|author|publisher|etc

3) when these are submitted they could see these above the next part of the form where they enter their details with the option to go back and delete/amend.
4) send all the info to my colleague.

if so has anyone seen a similar script that I could take a look @ to see if I can hack it to suit my needs?

Form Submission Fills Form Values With Garbage
I'm attempting to do some form processing on a server that has register_globals off, however, I've run into a confusing situation and need some help.

Basically, the form is a multi-part/form-data form as I have it upload a file in addition to submit a number of other fields, but the error I have occurs even when no upload is done.

When I submit the form, all my input field variables get filled with garbage. Here's the html before submission for one of the fields: Code:

Dynamic Form
I have one user table in my MySQL database and this is linked to a user type table containing 3 types of user. Each type of user will be required to give a different amount of data when registering.

Basically I want to create one registration form for all types of users but only show the form fields that are relevant to the individual user type. The user type will be selected from a pervious page containing a list menu with the 3 user types that is sent via GET to the registration page.

Dynamic Form
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 they press
next the form generates "How old are you?" 5 times on the page. The
customer will answer all 5 questions then press next. Finally, all the
local variables get dynamically created and written to a database.

I have already taken care of dynamically creating the question five
times. Using a simple WHILE clause, this generates the correct number
of questions. What I am having an issue with at this point, is how to
dynamically create the local variables.For instance, for the question
"How old are you?" I would need a unique variable for each instance;
using something like $Age(n). So that for five times, it would
automatically created variables $Age1 through $Age5. I have carried
over the number to the submit page by creating the variable $Number
and passing it along as hidden button on the form. $Age'$Number'
seemed to work for creating the variable, but $_post["Age'$Number'"]
doesn't work for referencing the global variable. I would need some
way of looping through and dynamically creating the variables.

Dynamic Form
I had to make a form for someone, with 42 questions each question had different form-elements. I was typing and coding for almost 3 hours..!! lets say we would make a form (formmaker.php) to dynamicly create a form with multiple questions: on the formmaker :

-first we have to enter the number of questions (max 100)
-then we have to type the question(s) in (an) input field(s)
-then we would have to select a type of answering field (textbox, checkbox, radiobuttons, file, dropdown etc. )

-it would be nice if we could select to make the question mandatory or not.
-if we choose for checkboxes or radiobuttons , it would be nice to know how much of them (no limits here !) ok..limit it to 30

-when we have selected...for example..15 checkboxes, they have to dynamicly appear on the formmaker.
-for each checkbox or radiobutton, we have to enter a value.
-finaly we have to add an email adres to each question !!! (and a BCC field) (this way, we can use one form and split and send the data to multiple recipients..!!)

-also we have to be able to dissable or enable a question. (if dissabled, it wont show on the created form..

A nice template to show a filled in form is preferable.. It would be nice to store everything in a database tabel. (for each new form a new tabel in the database) question1 id active(yes/no) questiontext fieldtype mandatory(yes/no) radio_or_checkboxvalue1(rocv1) rocv2 rocv3 rocv4 rocv5 etc.... sendto_email bcc_email
I started with the code already...here it is: Code:

Values From A Form
I have a form (search.html) that has 1 textbox and 3 listboxes. When I submit this form to a php file (search_res.php), I am using $HTTP_POST_VARS to get the values which is fine.

But then in my php file(search_res.php) I again have a listbox with 2 options. When I choose either one of these options to display the search results either by "Price" or "Name" I lose the values of the main form (search.html). How can I keep these values from the main form in my search_res.php page?

Getting Form Values
I have so far been trying to get all selected check boxes on the page, quantity text fields and ordernotes text area to INSERT INTO my database but to no avail. Im using OBDC to add to the confusion.

I've tried to develop my 'product' script into some kind of a form, but now need to find out how to make the data i want variable so that i can send them into my database. Code:

List Subscribe Form
trying to make a simple subscribe form for an email list like so...

$to = "news-subscribe@mysite.org";
mail($to, "subscribe", "subscribe", "From:$subscribe
Reply-To:$subscribe");

but the email list never confirms the subscription by email so can't figure out whether its getting the email or not? nether the subject or body text are necessary, its the address that does the command, any ideas anyone?

Form Entry List
I have a form with one box into which users type a few words (an email address).

That entry is emailed to me. I need to copy each entry into one text file automatically so I do not have to copy them manually out of each email one at a time. The result would be one text file with the entries listed down the page, one by one.

Dynamic Form Value Modification
I was wondering if and then how to dynamically update form variables without having move between webpages

I am developing a print quoting system for a company and I want the options in list boxes to adapt based on the values of previous selection in the form. However it must happen immediatly without the whole page having to refresh.

For example if a person chooses paper size to be A4 then the next drop down list must only have options available for A4 pages.

I thought I would need to use Javascript for this but I can't find out how to access the server side mysql database so I get the feeling Javascript is the wrong option.

The whole site is programmed in php but php is server side so I don't don't think its possible using php specifically.

Dynamic Form Selects
How do you make dynamic for selects in php? It is in regards to a modify type scripts im writing in php/mysql.

So regular select drop downs look like so:

<select name=genericselect>
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

right, well if I was pulling info from a database, how would I make is so that the 'selected' value is dynamic and comes from the database? Im sure theres a simple way of doing this.

Getting Info Out Of Dynamic Form
I am using the following code to produce a dynamic form.

$result = mysql_query("SELECT id,weight,date FROM weekly_data WHERE
weight IS NULL AND subscr_id = '$toss' AND date <= now()");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
print"<table width=ï`%' id='catchup' border=&#390;' cellspacing=&#390;'
cellpadding=&#390;'>";
print "<form name='form1' id='form1' method='post'
action='catchupprocess.php'>";
print"<tr>";
print"<td></td>";
print"<td>Weight</td>";
print"<td>Date</td>";
print"<td>Waist</td>";
print"<td>Measure</td>";
print"<td></td>";
print"</tr>";
while ($row = mysql_fetch_array ($result)){
//echo $result;
print"<tr>";
print"<td>";
print"<input name='".$row['id']."' size=&#394;' type='text'
value='".$row['id']."'/>";
print"</td><td>";
print"<input type='text' size=&#396;' name='weight".$row['id']."'
value=''/>";
print"</td><td>";
print"<input type='text' size=&#3910;' value='".$row['date']."'/>";
print"</td><td>";
print"<input type='text' size=&#393;' name='waist".$row['id']."'
value=''/>";
print"</td><td>";
print"<input type='text' size=&#396;' value='$measure'/>";
print"</td><td>";
print"<input type='hidden' size=&#3910;' value=''/>";
print"</td>";
print"</tr>";
}
print"<tr>";
print"<td>&nbsp;</td>";
print"<td><input name='Reset' type='reset' value='Reset'></td>";
print"<td>&nbsp;</td>";
print"<td><input name='submitcatchup' type='submit'
value='Submit'></td>";
print"<td>&nbsp;</td>";
print"</tr>";
print"</form>";
print"</table>";
?>

Form With Dynamic Questions
I've a mysql table where i stored a list of questions. My php script
executes a query which yields a different number of questions every time; i
used the loop function to create an input field for each question in the
form; and dynamically referencing each input name with the question number
i.e. question 1 is called q1, question 2 named q2, and so on.
The data is submitted using POST. I then try to retrieve all the answers by
doing a loop and using something like echo '$_POST['q'.$n.'']' except the
syntax doesnt seem to work.

Dynamic Form Update
I have the following form in which i need to updateitems.
The problem is that i do not know how many elements will be in the form
(generated dynamically)

eg
<input type = "hidden" name ="id1" value="1"><input type ="qty1" value ="1">
<input type = "hidden" name ="id2" value="2"><input type ="qty2" value ="1">
<input type = "hidden" name ="id3" value="3"><input type ="qty3" value ="5">
<input type = "hidden" name ="idn" value="n"><input type ="qtyn" value ="1">

how do i generate an array for a foreach loop to update the values in PHP
so that i can use it to create a Update query
eg
///begin loop
$sql = "UPDATE `table` SET `qty` = `$qtyn` WHERE `id` = `$idn`";
// end loop

Dynamic Form Items
I am trying to create A form that its fields will depend on a
form menu.
for example.
/***********************************************/
<form name="form1" method="post" action="">
<select name="select">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>

Text field 1<input type="text" name="textfield">
Text Field 2<input type="text" name="textfield2">
Text Field 3 <input type="text" name="textfield3">
Text Field 4 <input type="text" name="textfield4">

<input type="submit" name="Submit" value="Submit">
</form>
/***********************************************/
When the option 1 is selected only the textfields 1 and 2 to appear,
when option 2 is selected only textfields 1 and 3 to appear and so on... any
combination I would like.

I tried puting the textfields in "if" statments but i don't like it. its too
messy PHP and HTML code.
Any Ideas of how this could be done better ? If someone did something
similar before and has a relative link it would be good as well.

Dynamic Form Pulldown
I'm building a form and need to have the options in a pulldown menu pulled from a mysql database, i understand the basics of sql and have used forms before, i just need to see an example to get me on my way.

Dynamic Form Processing
Im writing a script for processing a form created by a csv file. this form is created through a loop, where $num is the place in the loop. Code:

Dynamic Form Fields
I want to have it setup so when the user clicks this link a value is sent via get and that value is put through a for loop to generate an additional form field: Code:

Dynamic Form And $_REQUEST
My current project needs to run on both windows and linux. I figured out that windows needs $_REQUEST to read the form elements. This worked well until parsing a dynamically built form with checkboxes named: cb0, cb1, cb2, etc.

I can't figure out how I can use $_REQUEST to read the form elements, when I try $_REQUEST[$i] for example all values of the array elements are 'cc'. No idea where this comes from as cc is never used as a value?

Remember Form Values
I have a form, and I'm using PHP to make sure the users filled in certain fields. If they haven't filled in a field, they are brought back to the form after submitting (using header location) and asked to fill it in. However, when they go back, the form values are all gone.

How can I keep the form values there? I know i've seen it done, but I can't remember where.

Form Values Disappearing
I have a form which users are supposed to enter information into

Naturally there is an extensive error-checking on the form-input.

If an user eg. forgets to enter information into a field an errorpage will be included with the information. Normally it would be possible to press the back-button of the browser to return to the form holding the values of which it was submitted.

Retaining Form Values
I have the form values set to value="<? php echo $Name ?>".

I need to allow a person to access a presentation from within this test form if for example they are unsure of an answer they can return back to the presentation.

I need to retain what they have answered on the form b4 they choose to go out to presentation when they come back. If they only use the back button, values are retained but if they reselect to take the test, I loose all.

I need to save values off when they select link back. Can anyone give me an easy way. I guess I could write to D.B. file with save values and read back in but is there a simpler way?

Saving Form Values
I want to fill in a form in php and for some fields i would like to go to another php page within the same frame. There i can lookup a key to place into a formfield in the previous php page. Well when i return with the lookupped value all the values already entered in this page are missing. So i was trying to save this values temporary within $_SESSION vars. I filled this with a javascript (with an onblur-function) but i am unable to manipulate the $_SESSION vars within javascript. Because php is serverbased.

Remembery Form Values!
I have seen a lot of posts around here lately on how to remember form values after the user hits "submit" [so that they can be corrected]. Well the method that I use is very simple: I store my form in a function, and then when I need to display it I just call that function. After a presses submit, I just display the form the submitted values in it. PHP Code:

HTTP Form Values
On one page I have checkboxes being selected and then submited via a form post. The problem is the values and names of the checkboxes change each time the script is ran. So I have to know what they are to call them on the next page. Is there any way to retrieve all the HTTP passed variables in php that where passed without knowing the variable name?


Copyright © 2005-08 www.BigResource.com, All rights reserved