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!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i'm trying to retrieve javascript parameter's value in php. So i created a function which send an array to my controllers. and i tried to do this:
function formulaireAction()
{
$this->view->title = "formulaire d'inscription";
if ($this->_request->isPost())
{
$res=$this->_request->getPost('tabs_coords');
$fields= explode(',',$res);
foreach ($fields as $v)
{
$this->view->message=$v;
}
$this->render();
}
}
and when i tested the value of my array are not dispayed. i make some test to make sure that the array that i'm sending is not empty. so i don't see where the problem is. can you help me?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i tried print_r() and it displays nothing, i tested if my array was empty or not before submitting my form. and it wasn't empty. the problem is when i try to retrieve it seem that my array is empty. i don't know what's the problem. any idea
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
yes i'm sure of sending a post request. i used a function which send an array in a hidden input
[syntax="javascript"]
function setValue()
{
document.getElementById("tabs_coords").value=tab.toString();
}
tab is my array which wasn't empty. and created my form like this
and i tried to pass in my javascript function a simple string and it worked well. for the moment the problem is focused in how to send an array from javascript to php. is there any other solution to let me send an javascript array to php?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
nahydy wrote:i tried print_r() and it displays nothing, i tested if my array was empty or not before submitting my form. and it wasn't empty. the problem is when i try to retrieve it seem that my array is empty. i don't know what's the problem. any idea
it's kind bizarre this time print_r shows me this error
Function name must be a string in /var/www/test/pixels/application/controllers/IndexController.php on line 125
i don't understand the last time i used print_r doesn't cause any error and i'm sure that i have nothing changed since . i don't really understand what may cause this problem.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ok this is the code :
[syntax="html"]
<html>
<head>
<title><?php echo $this->escape($this->title); ?></title>
<script type="text/javascript">
tab1=new Array();
function remplir()
{
tab1.push('na');
tab1.push('yai');
tab1.push('cee');
}
remplir();
function afficher_t()
{
var arv = tab.toString();
alert(arv);
}
function setValue()
{
var arv = tab1.toString();
document.getElementById("tabs_coords").value=arv;
}
</script>
</head>
<body >
<table>
<tr>
<td>
<p>Map de pixels</p>
</td>
</tr>
<tr>
<td>
<form action="<?php echo $this->baseUrl ?>/index/formulaire/" method="POST" id="form1" onsubmit="setValue();">
<input type="text" value="" name="idText" />
<div id="Canvas" style="position:realtive;height:5px;width:5px;">
<img alt="map_pixels" src="<?php echo $this->baseUrl;?>/public/images/main.png" style="position: relative; top: 70px; left: 30px; visibility: visible;" usemap="#main" width="1000" height="1000"/>
</div>
<input type="hidden" name="tabs_coords"/>
<input type="button" name="afficher" value="afficher" id="afficher" onclick="javascript:afficher_t();" />
<input type="submit" value="submit" id="submit"/>
</form>
</td>
</tr>
</table>
</body>
</html>
and in my controllers i do this to get the array value:[/syntax]
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]