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.
17 4335 @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: -
<input name="my_array[]" value="1" />
-
<input name="my_array[]" value="2" />
-
<input name="my_array[]" value="3" />
-
<input name="my_array[]" value="4" />
-
And to access those elements in PHP, you do something like so: -
print_r($_POST['my_array']);
-
-
foreach($_POST['my_var'] as $key => $my_var) {
-
printf("Key #%d has the value <strong>%s</strong>", $key, $my_var);
-
}
-
Mark.
now I have problem with imploding it - 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?
Seems like $pod_albumom_photo_id is not an array. What does var_dump($pod_albumom_photo_id); produce?
it produces
string(4) "12"
thats number of my inputs (4) and value from the last. "12"
@Alino
No, that can't be right; 4 should be the length of the string, and it says 'string' not 'array'. :S
so what i have to do to have it in array? :P
@Alino
put empty brackets at the html form input name.
i have done that already, my code looks like - <script type="text/javascript">
-
-
function addfile()
-
{
-
var obj = document.getElementById("sprytextfield2").cloneNode(true);
-
document.getElementById('upfiles').appendChild(document.createElement('br') );
-
document.getElementById('upfiles').appendChild(obj);
-
}
-
-
</script>
- <fieldset class="border" id="upfiles">
-
<legend>Vymazať fotku v profile pod albumom:</legend>
-
<label for="pod_albumom_photo_id[]">ID fotky:</label><br />
-
<span id="sprytextfield2">
-
<input type="text" name="pod_albumom_photo_id[]" value="" onKeyPress="ipt_onkeypress()" />
-
<span class="textfieldInvalidFormatMsg">Iba cifry prosím. </span></span>
-
<input class="button" type="button" value="Pridať pole" onclick="return addfile()" />
-
</fieldset>
and in my form process page: - foreach($_POST['pod_albumom_photo_id'] as $key => $pod_albumom_photo_id)
-
{
-
printf("Foto s ID <strong>%s</strong> bude vymazaná<br />", $pod_albumom_photo_id);
-
}
-
$x = implode(" ", $pod_albumom_photo_id);
now i just need to get it work, that implode.
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
man thank you, you make my day :) it just works !!! :D:D
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?
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
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 - ...
-
$handle = fopen("$filepath", 'w+');
-
if($handle)
-
{
-
-
$all_what_to_do =
-
"<html>
-
<head><title>new html file</title></head>
-
<body>
-
-
</body>
-
</html>"
-
;
-
-
if(!fwrite($handle, "$all_what_to_do"))
-
die("couldn't write to file.");
-
...
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
I am still seeking for help
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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=...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
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...
|
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...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
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...
|
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...
|
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...
|
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...
| |