Jump to content

Retrieve information from $_POST


dhope

Recommended Posts

Hi,

 

Is it possible to retrieve all the information from a posted value without knowing the input field?

 

My page is taking information from a database and then creates a page with checkboxs so that people can select certain fields. There are 1300 fields in the database so I don't know what fields will be submitted when a person saves the page,  is there a simple way to check what fields have been submitted without writing a check for each checkbox?

 

I hope this makes sense, thanks in advance for any help.

Link to comment
Share on other sites

Checkbox data should be in an array within post.

 

<input type='checkbox' name='checkboxes[]' value='value1' />
<input type='checkbox' name='checkboxes[]' value='value2' />
<input type='checkbox' name='checkboxes[]' value='value3' />

 

Then you can just loop through the $_POST['checkboxes'] array

 

From a usability standpoint... I'm not sure I would want to fill out a form with 1300 checkboxes :)

Link to comment
Share on other sites

This might be what you're looking for

 

foreach ($_POST as $key => $value) {
   if (isset($value)) {
       do something with the input
   }
}

 

It checks all posted values and looks to see if it's set. If it is it does something with the value.

If I'm not understanding correctly, my apologies.

 

From a usability standpoint... I'm not sure I would want to fill out a form with 1300 checkboxes :)

 

Totally agree

Link to comment
Share on other sites

The checkboxs are split up into sections making it much easier to use :)

 

I have tried the examples posted but it only seems to print out the last checkbox to be selected, any ideas?

 

CODE:

 

if(isset($_GET['update_towns'])) {

 

foreach ($_GET as $key => $value) {

 

print "$value";

 

}

}

Link to comment
Share on other sites

Yes, I have set a hidden field to update_towns so that I can check if the form has been submitted, i'm not sure if there is a better way of doing this.

 

The foreach doesn't seem to loop through it just seems to print out the final checkbox that was selected.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.