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
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_");

Link to comment
Share on other sites

  • 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!

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.