472,348 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

How to get all set $_post ?

25
So I have a javascript on my page, which makes me able to add another input text field when I click on a button. And it's named "test" when I click the button it creates another input named test1, on another click it creates test2 and so on... But I have a problem on my form processing page, I need to get know which is the last "test" and also I need to set variables for each of them. I imagine some small code which will make something like this for me:

$test = $_POST('test');
$test2 = $_POST('test2');
$test3 = $_POST('test3');
$test4 = $_POST('test4');

And it will go on until last test. Thanks for helping me.
Aug 4 '09 #1
17 4335
Markus
6,050 Expert 4TB
@Alino
There is a solution to this problem of yours - you can have your input elements become an array, that is to say, you can access them as an array inside the post array. To do this, you simply name the elements the same, and append '[]' to them, like so:

Expand|Select|Wrap|Line Numbers
  1. <input name="my_array[]" value="1" />
  2. <input name="my_array[]" value="2" />
  3. <input name="my_array[]" value="3" />
  4. <input name="my_array[]" value="4" />
  5.  
And to access those elements in PHP, you do something like so:

Expand|Select|Wrap|Line Numbers
  1. print_r($_POST['my_array']);
  2.  
  3. foreach($_POST['my_var'] as $key => $my_var) {
  4.     printf("Key #%d has the value <strong>%s</strong>", $key, $my_var);
  5. }
  6.  
Mark.
Aug 4 '09 #2
Alino
25
thank you man, it works
Aug 6 '09 #3
Markus
6,050 Expert 4TB
@Alino
No problamo.

Mark.
Aug 6 '09 #4
Alino
25
now I have problem with imploding it
Expand|Select|Wrap|Line Numbers
  1. implode(" ", $pod_albumom_photo_id);
I receive the following error message then:
Warning: implode() [function.implode]: Invalid arguments passed in /storage/www1/9/site46049/wwwroot/xxx/process.php on line 90
what's wrong? ;[ how to fix it?
Aug 6 '09 #5
Markus
6,050 Expert 4TB
Seems like $pod_albumom_photo_id is not an array. What does var_dump($pod_albumom_photo_id); produce?
Aug 6 '09 #6
Alino
25
it produces
string(4) "12"
thats number of my inputs (4) and value from the last. "12"
Aug 6 '09 #7
Markus
6,050 Expert 4TB
@Alino
No, that can't be right; 4 should be the length of the string, and it says 'string' not 'array'. :S
Aug 6 '09 #8
Alino
25
so what i have to do to have it in array? :P
Aug 6 '09 #9
dlite922
1,584 Expert 1GB
@Alino
put empty brackets at the html form input name.
Aug 6 '09 #10
Alino
25
i have done that already, my code looks like
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. function addfile()
  4. {
  5. var obj = document.getElementById("sprytextfield2").cloneNode(true);
  6. document.getElementById('upfiles').appendChild(document.createElement('br') );
  7. document.getElementById('upfiles').appendChild(obj);
  8. }
  9.  
  10. </script>
Expand|Select|Wrap|Line Numbers
  1.         <fieldset class="border" id="upfiles">
  2.         <legend>Vymazať fotku v profile pod albumom:</legend>
  3.         <label for="pod_albumom_photo_id[]">ID fotky:</label><br />
  4.         <span id="sprytextfield2">
  5.         <input type="text" name="pod_albumom_photo_id[]" value="" onKeyPress="ipt_onkeypress()" />
  6. <span class="textfieldInvalidFormatMsg">Iba cifry prosím. </span></span>
  7.         <input class="button" type="button" value="Pridať pole" onclick="return addfile()" />
  8.         </fieldset>
and in my form process page:
Expand|Select|Wrap|Line Numbers
  1.             foreach($_POST['pod_albumom_photo_id'] as $key => $pod_albumom_photo_id)
  2.             {
  3.             printf("Foto s ID <strong>%s</strong> bude vymazaná<br />", $pod_albumom_photo_id);
  4.             }
  5.             $x = implode(" ", $pod_albumom_photo_id);
now i just need to get it work, that implode.
Aug 6 '09 #11
dlite922
1,584 Expert 1GB
When you do a foreach, you're already "imploding" in a sense.

$_POST['pod_albumom_photo_id'] /is/ an array (do a var dump if you don't' believe me)

What do foreach's do? traverse arrays? to what? strings. thus $pod_albumom_photo_id is a string.

If you want it to be an array, just assign what's in the post:

$pod_albumom_photo_id = $_POST['pod_albumom_photo_id'];

TADA! you've got an array now you can implode.



Dan
Aug 6 '09 #12
Alino
25
man thank you, you make my day :) it just works !!! :D:D
Aug 6 '09 #13
Alino
25
my next problem is creating link of this $pod_albumom_photo_id
I wanted it to implode to be able to make link like
implode($iframe_part1 . "http://www.mywebpage.com/x.php?action=100&uid=" .$user_id. "&iid=", $pod_albumom_photo_id);
but then i noticed that i am not able to make those links because i can't add
$iframe_part2
after array. How to solve this?
Aug 7 '09 #14
dlite922
1,584 Expert 1GB
I don't get your question. Why can't you add a variable?

It looks like you're doing complex string building, why not stick with the foreach?

What is your expected results? What are your inputs and what do you want output? Give sample data.

Thanks,




Dan
Aug 7 '09 #15
Alino
25
that form on my page creates new html page, and in that html should be iframes with urls and in those urls are values from $pod_albumom_photo_id

so i was trying to implode that array to create those iframes, but it didnt close each iframe correctly only the last.

i am using this to write to new html file
Expand|Select|Wrap|Line Numbers
  1. ...
  2. $handle = fopen("$filepath", 'w+');
  3.         if($handle)
  4. {
  5.  
  6.     $all_what_to_do =
  7.              "<html>
  8.              <head><title>new html file</title></head>
  9.              <body>
  10.  
  11.             </body>
  12.             </html>"
  13.             ;
  14.  
  15.             if(!fwrite($handle, "$all_what_to_do"))
  16.             die("couldn't write to file.");
  17. ...
it works pretty good but
i don't know what to put inside body tag, to create those iframes with url in which are those values from $pod_albumom_photo_id
Aug 7 '09 #16
Alino
25
I am still seeking for help
Aug 10 '09 #17
Alino
25
nah i don't need help anymore, i found myself stupid and now i know how to do that, thanks to all for helping me guys, you are all really cool.
Aug 10 '09 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Adrian Parker | last post by:
Is it possible to click on a button, and not have it's value and name stored in _POST? I have this script with a button on it. When you click...
4
by: Kevin | last post by:
I am having problems in my php code. I am relatively new to php but I know some basics. This is the problem: when i try to echo some...
15
by: zorro | last post by:
greetings... I'm wondering what more advanced coders would think ot this: $_POST = clean($_POST); and now I can use POST directly: $sql=...
7
by: Dynamo | last post by:
I am using values stored an $_POST array to display records from a table before asking the user if he is sure he wants to delete them. If the user...
1
by: RDizzle | last post by:
okay. so all i am doing is changing a registration script that uses $_GET to a script that uses $_POST, but the validation script now returns NULL...
6
by: comp.lang.php | last post by:
I have no idea why this is happening and I need someone to explain this to me at the simplest level absolutely possible (pretend I'm a 10-year old...
5
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST...
3
by: scabman | last post by:
Working on upgrading a site and after moving everything onto a test server (localhost) things started to get real buggy. Went through and checked all...
12
by: Todd Michels | last post by:
Hi all, I am trying to send data from a form and insert it into a MSSQL DB. When I submit the data I get: Warning: mssql_query() : message:...
5
Tarantulus
by: Tarantulus | last post by:
Hi, ok, quick description of the problem, I'm trying to reference the postdata from some checkboxes. Unfortunately the checkboxes are dynamically...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.