Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Form

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Form

Postby elitecodex » Thu Sep 26, 2002 8:26 am

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
elitecodex
New php-forum User
New php-forum User
 
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA

Postby DoppyNL » Thu Sep 26, 2002 9:23 am

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: Select all
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
DoppyNL
 

Postby elitecodex » Thu Sep 26, 2002 11:19 am

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
elitecodex
New php-forum User
New php-forum User
 
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA

Postby Jay » Thu Sep 26, 2002 12:48 pm

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! ;)
Jay
 


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.