multiple form controls with same name
Posted: Fri Feb 23, 2007 2:25 pm
I got multiple submit buttons with same name CreateCat and i seperate them by CreateCat[#]. how do i tell which button is pushed?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<script language="JavaScript">
function checkMe( tVal ){
alert( tVal );
}
</script>
Code: Select all
<form action="index.php" method="get" name="form1">
<input name="CreateCat" type="button" value="1" onclick="checkMe( this.value );" />
<input name="CreateCat" type="button" value="2" onclick="checkMe( this.value );" />
<input name="CreateCat" type="button" value="3" onclick="checkMe( this.value );" />
<input name="CreateCat" type="button" value="4" onclick="checkMe( this.value );" />
<input name="CreateCat" type="button" value="5" onclick="checkMe( this.value );" />
</form>
You didn't mention server side.psychotomus wrote:that does nothing on server side.
Code: Select all
echo '<HR><PRE>'; print_r($_POST); echo '</PRE>';
echo '<HR><PRE>'; print_r($_GET); echo '</PRE>';That should be part of it. Imagine that you have an array. You want to look through that array to check a value.psychotomus wrote:by using count?
Code: Select all
list($cat_id) = each($_POST['CreateForum']);
$cat_id = intval($cat_id);
$forumname = stripslashes($_POST['textForumName'][$cat_id]);Code: Select all
if(isset($_POST['CreateForum']))You can use is_array(), or you can var_dump() or print_r() before looping it to see what is in it. And if you try to use isset($_POST)... well, why not try it and tell us if it will work?psychotomus wrote:i get an error if its not posting any data
Warning: Variable passed to each() is not an array or object in /mounted-storage/home40b/sub002/sc18478-RGIJ/mywebsite/admin/forum-manage.php on line 20
i tried adding anbut that didn't help. is there a way to tell if a form is just being posted? like if(isset($_POST)) ?Code: Select all
if(isset($_POST['CreateForum']))