My doubt is how to read array elements recived via $_REQUEST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ullasvk
Forum Newbie
Posts: 21
Joined: Fri Feb 13, 2009 11:55 pm

My doubt is how to read array elements recived via $_REQUEST

Post by ullasvk »

i have a form where user can add rows using javascript. i have another page which takes value from the above said form.My doubt is how to read array elements recived via $_REQUEST..

PLEASE ANY ONE HELP ME.
NOmeR1
Forum Newbie
Posts: 8
Joined: Sat Feb 14, 2009 8:32 am

Re: My doubt is how to read array elements recived via $_REQUEST

Post by NOmeR1 »

$_REQUEST can contain array if you sent it
For example:
First page (generating and sending fields)

Code: Select all

<script>
function addfield() {
    document.getElementById('fields').innerHTML += '<input type="text" name="array[]"><br>';
}
</script>
<form method="POST" action="second.php">
<div id="fields">
<input type="text" name="array[]"><br>
</div>
<input type="button" value="Add field" onclick="addfield()"><br>
<input type="submit" value="Submit">
</form>
Second page (second.php)

Code: Select all

<?php
if(isset($_REQUEST['array'])) {
    foreach($_REQUEST['array'] as $element) {
        echo $element.'<br>';
    }
}
?>
Post Reply