Jump to content

Easier way to extract Form Variables??


rossdeane

Recommended Posts

Hi People,

Wonder if you can help me out..

I'm currently doing a few forms in php, and they can be quite large.

The problem I have is that its very time consuming and boring to extract all the form fields into variables, for example

 $someformfield= $_POST['someformfield']; 

I've been doing a separate line for each field and just putting it in a separate include file for neatness, but surely theres a quicker way than doing this 50+ times?  ???

I considered just naming the fields with numbers and then extracting each one inside a loop, but its not ideal because it would make the form code confusing...

Any help appreciated,

thanks

Ross

Link to comment
https://forums.phpfreaks.com/topic/113581-easier-way-to-extract-form-variables/
Share on other sites

$_POST is already an array variable. $_POST['someformfield'] is a perferctly fine variable name. Assinging $someformfield = $_POST['someformfield'] is a waste of processor time and just doubles the amount of variable storage space needed.

 

If you really want to do this, use the extract() function with the EXTR_PREFIX_ALL parameter and a $prefix string, something like -

 

extract($_POST, EXTR_PREFIX_ALL, "form_");

  • 2 weeks later...

hi,

the simple solution is using for each loop on $_Request(it is a request array that contains the form data being to be submitted)

for example

foreach($_Request as $key=>$value)

{

$InsertArray = $Value;

 

}

and than using this $InsertArray, you can insert a records into the specifice table of your DB.

Hope it it will give you some idea.

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.