ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ok I've got an html page that has about 100 variables to be passed to a php script which emails all of these variables to me. All of them are named choice1,choice2,choice3,etc..
Instead of writing like 100 lines or more of code, I thought I'd use a for loop, only I'm not sure how to do this... I have tried :
$post_array[$i] = $_POST['choice' . $i];
and
$post_array[$i] = $_POST['choice$i'];
and
$post_array[$i] = $_POST['choice'$i];
I would name the field like this :
<input type="text" name="choice[0]" value="" />
<input type="checkbox" name="choice[1]" checked="true" />
<input type="radio" name="choice[2]" />
...
Umm...sorry. I dont follow, I'm trying to ..but I dont quite understand how I could use that with like a for loop, if say I had 100 variables being passed. The answers probably right there...but I'm not that great at PHP, only been at it a few months.
Originally posted by WindowsBurner
$post_array[$i] = $_POST['choice' . $i];
and
$post_array[$i] = $_POST['choice$i'];
and
$post_array[$i] = $_POST['choice'$i];
As you already know, those won't work, but this will:
Why not change the variable names in the HTML to something useful and then do away with all that nonsense by just emailing yourself with something like this:
Code:
$recipient = "you@your.com";
$headers = "From: WebServer on " . $_SERVER['HTTP_HOST'] . " <you@your.com>\n";
$subject = "A really cool subject\n";
$redirectHeader = "Location: http://" . $_SERVER['HTTP_HOST'] . "/thankYou.php";
$body = "The form was filled out with the following:\n\n";
while(list($key, $val) = each($_POST)) {
$body .= $key . ": " . $val . "\n";
}
mail($recipient, $subject, $body, $headers);
header($redirectHeader);
You already have $post_array in $_POST. Reassigning all the values into another array is just a waste of CPU cycles and memory.
Thanks corcommander, I knew I was close...but I hadn't thought of that.
sigsegv, your right I could do it that way. I hadn't thought of that either, what I have is a form for a survey and
there is literally 100 or more options. And I wanted a way for it to send me the info using as few lines of code as possible.
So, thanks a lot guys. I hadn't expected my post to get all these wonderful posts, I figured I'd quite one or two quick ways around the problem. Thanks alot.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.