multiple form controls with same name
Moderator: General Moderators
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
multiple form controls with same name
I got multiple submit buttons with same name CreateCat and i seperate them by CreateCat[#]. how do i tell which button is pushed?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
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>
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
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>';- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
ok. i managed to find some code that will get the id of the control
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 an but that didn't help. is there a way to tell if a form is just being posted? like if(isset($_POST)) ?
Code: Select all
list($cat_id) = each($_POST['CreateForum']);
$cat_id = intval($cat_id);
$forumname = stripslashes($_POST['textForumName'][$cat_id]);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 an
Code: Select all
if(isset($_POST['CreateForum']))- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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']))