Form

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
I have a dropdown box that contains multiple selections... I want to be able to save this to a database. My form method is POST... when i tried to save it, it did a var_dump($_POST); and it will only save what is selected... if nothing is selected, it wont pass anything. How can I get the contents of the form object?

Any input is greatly appreciated. Thanks.

Will
 
as far as I know, html only posts data wich is selected, so if nothing is selected it will post absolutely nothing.

to prevent you're script from (possibly) failing you can check if a variable is posted or not with:
Code:
if (isset($_POST['variable']))
{
   blablabla;
}

You can also use javascript or something to check if something is actually selected or not before the form is posted, this is not foulproof though.


How can I get the contents of the form object?
if nothing was selected: not via $_POST
if something was selected: the selected items via $_POSt
for all values you will either have to select everything :twisted:

you can also just look in the original form and get you're data from there.


anyway, I can't see you're actual problem :cry: you're not getting something from you're form, but you know the contents of you're form, so.... I don't really get it :roll: :(

Greetz Daan
 
Ok, Ill try to explain in more detail. Im writing a statistics program that has an ip filter. Basically, it will exclude certain ip ( or patterns ) from the stats it collects. Currently, I have it stored in a php file where one would have to enter the data in a syntax-correct array. I want to store the ip patterns in a database, and then populate an array with that data. In order to edit that data, I have a dropdown box containing each ip.. and buttons to either add or delete from the list. That works fine, but when you go to save it, it wont send the data unless its selected. Even if it selected, it only sends one, not all of them. Im trying to achieve each item in the list to save to the database.

I hope that makes more sense. I would show you the source, but my webhost has recently been unavailable due to misconfiguration of the their mysql server.

Thanks.

Will
 
Name the item as an array (ie dropdown[] instead of dropdown). When the form send the info, it'll send all the (selected) values within the $_POST['dropdown'] array so you can pick them off one by one.

What you want is a piece of javascript that will use the onSubmit action to automatically select everything in that menu! I'll leave the rest for you to work out, shouldn't be hard now! ;)
 
Back
Top