Jump to content

[SOLVED] colllecting unknown varial names and changing them


Recommended Posts

Is there anyway of collecting the variables submitted by a form and renaming them.

Problem is they all have the same name with a number afterthem example ver0 ver1 ver2 ver3 ver4 to ver10 but there is no way of knowing which of these variables have been submitted??

Here's how to grab all of the posts and print the name of the variable (notice the double $$) and value.

 

foreach ($_POST as $key => $value) {
  echo "Name of var: " . $$key . " value: " . $value;
}  

 

Hope this helps.

 

* You should have posted this in PHP Help not Regex unless someone has a regex answer...

sorry i thought i had posted in php help

 

my problem is this row

echo '<tr><td><input type="checkbox" name="news'.$i.'"  value="'. $mtitle. '"  /></td><td width="90% align="left">'. $mtitle. '</td></tr>';

$i++;

}

 

when it posts there are 20 choices to choose from and the select values come out as new0 to news20 so on my submit form it is impossible know which valiue to put in the ($HTTP_POST_VARS["    "]); section as the values change each time the form is submitted. I have been working this for more than 20 hours now and to no avail I am thinking there is a simple solution like maybe an onselct function name='' else name=  on the form this is driving me nuts.

 

echo '<tr><td><input type="checkbox" name="news[]"  value="'. $mtitle. '"  /></td><td width="90% align="left">'. $mtitle. '</td></tr>';
$i++;
}

 

That will put it in an array and $HTTP_POST_VARS is depreciated, use $_POST instead. This will return an array of news items, so $_POST['news'][0] will give you the first item etc.

Worth noting..

 

if on the form you use a name with square brackets it will work as an array ie

<input type="test" name="test[]">

<?php
echo "found ".count($_POST['test']);
print_r($_POST['test'])
?>

 

Honestly, this was solved 3-4 posts ago. I was just re-iterating that point.

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.