View previous topic :: View next topic |
Author |
Message |
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Tue Jul 29, 2003 5:14 pm Post subject: Multiple Form Issue |
|
|
Is there a Smarty problem with using multiple form values with the same name? For instance, I have a script that outputs many records so a user can delete or edit the records in a database, normally I would use something like this to capture the values for all of fields into an array:
Code: | <input type="text" name="userId[]"> |
userId would then contain the values of the form in an array, but I'm not getting that result now, all I get is the last record in the form instead of the array. Any suggestions? _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
marco5 Smarty Rookie
Joined: 28 Jul 2003 Posts: 19
|
Posted: Tue Jul 29, 2003 5:41 pm Post subject: Re: Multiple Form Issue |
|
|
reformed1 wrote: | Is there a Smarty problem with using multiple form values with the same name? For instance, I have a script that outputs many records so a user can delete or edit the records in a database, normally I would use something like this to capture the values for all of fields into an array:
Code: | <input type="text" name="userId[]"> |
userId would then contain the values of the form in an array, but I'm not getting that result now, all I get is the last record in the form instead of the array. Any suggestions? |
input type="text" does support Multiple name(maybe,i need to say not support very well)
in ur case,u should use this script to handle
Code: |
<?
for($i=0;$i<=10;$i++){
if($_POST['userId'][$i]==""){
break;
}else{
echo $_POST['userId'][$i]."<br>";
}
}
?>
|
|
|
Back to top |
|
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Tue Jul 29, 2003 5:48 pm Post subject: |
|
|
My problem is that I'm not getting any values, except the last one in the form. Your script will definately help handle an emtpy array, but I'm trying to find out why my array is empty. Do mulitiple values work with the get method? Maybe that's my problem. Also, I'm using the print_r('userId') function to look at my array. _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
marco5 Smarty Rookie
Joined: 28 Jul 2003 Posts: 19
|
Posted: Tue Jul 29, 2003 5:50 pm Post subject: |
|
|
reformed1 wrote: | My problem is that I'm not getting any values, except the last one in the form. Your script will definately help handle an emtpy array, but I'm trying to find out why my array is empty. Do mulitiple values work with the get method? Maybe that's my problem. Also, I'm using the print_r('userId') function to look at my array. |
oic.
i am understanding ur question now
cause u have not assign a value to the userId
normally,it should like this
<input type="text" name="userId[]" value="sth"> |
|
Back to top |
|
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Tue Jul 29, 2003 6:01 pm Post subject: |
|
|
Actually I am using a value. Sorry I didn't put it in my last post. Here is part of the code i'm using.
Code: | <input name="hours[]" type="text" size="6" maxlength="5" value="{$info.1}"> |
{$info.1} is coming from my database. _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
marco5 Smarty Rookie
Joined: 28 Jul 2003 Posts: 19
|
Posted: Tue Jul 29, 2003 6:03 pm Post subject: |
|
|
reformed1 wrote: | Actually I am using a value. Sorry I didn't put it in my last post. Here is part of the code i'm using.
Code: | <input name="hours[]" type="text" size="6" maxlength="5" value="{$info.1}"> |
{$info.1} is coming from my database. |
sorry!!
do u mind posting ur php handling code |
|
Back to top |
|
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Tue Jul 29, 2003 6:06 pm Post subject: |
|
|
I don't have any handline code yet because I have nothing to handle. I'm just using print_r() at this point to see the array. _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
marco5 Smarty Rookie
Joined: 28 Jul 2003 Posts: 19
|
Posted: Tue Jul 29, 2003 6:09 pm Post subject: |
|
|
reformed1 wrote: | I don't have any handline code yet because I have nothing to handle. I'm just using print_r() at this point to see the array. |
have u assign the value to info^^?
i mean this:
$Smarty->assign("info",xxx); |
|
Back to top |
|
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Tue Jul 29, 2003 6:15 pm Post subject: |
|
|
The value of {$info.1} is coming from my database along with many others for the other fields in my form. _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
marco5 Smarty Rookie
Joined: 28 Jul 2003 Posts: 19
|
Posted: Tue Jul 29, 2003 6:19 pm Post subject: |
|
|
um
whatever happens u must to run this function $xx->assign() |
|
Back to top |
|
marco5 Smarty Rookie
Joined: 28 Jul 2003 Posts: 19
|
Posted: Tue Jul 29, 2003 6:29 pm Post subject: |
|
|
this is an example for u
[php:1:5a33872ec2]
<?php
//test.php
require_once("./libs/Smarty.class.php");
$tpl=new Smarty;
$tpl->assign("info",array(1,2,3,4));
$tpl->display("test.tpl");
?>
[/php:1:5a33872ec2]
Code: |
{*test.tpl*}
<input name="hours[]" type="text" size="6" maxlength="5" value="{$info.1}">
|
it will be output:
Code: |
<input name="hours[]" type="text" size="6" maxlength="5" value="2">
|
|
|
Back to top |
|
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Tue Jul 29, 2003 6:34 pm Post subject: |
|
|
I'm getting my values from the database with no problem, because I can see the values in my form. I know that values are there, they are just not passing in an array to my print_r() statement. _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
marco5 Smarty Rookie
Joined: 28 Jul 2003 Posts: 19
|
Posted: Tue Jul 29, 2003 6:38 pm Post subject: |
|
|
reformed1 wrote: | I'm getting my values from the database with no problem, because I can see the values in my form. I know that values are there, they are just not passing in an array to my print_r() statement. |
i have told u that <input type="text"> does support multiple name!!
it does not like checkbox,radio!! |
|
Back to top |
|
marco5 Smarty Rookie
Joined: 28 Jul 2003 Posts: 19
|
Posted: Tue Jul 29, 2003 6:45 pm Post subject: |
|
|
if u want to use multiple name
,u should use this script to handle.like this
[php:1:3f0a0b84fc]
<?php
if($_GET['action']==""){
echo "<form action=$_SERVER[PHP_SELF]?action=1 method=post>";
for($i=0;$i<20;$i++){
echo "$i:<input type=text name=hk[] value=$i><br>";
}
echo "<input type=submit>";
echo "</form>";
}else{
echo "this is the result:<br>";
for($i=0;$i<count($_POST['hk']);$i++){
if($_POST['hk'][$i]==""){
continue;
}else{
echo $_POST['hk'][$i]."<BR>";
}
}
}
?[/php:1:3f0a0b84fc] |
|
Back to top |
|
marco5 Smarty Rookie
Joined: 28 Jul 2003 Posts: 19
|
Posted: Tue Jul 29, 2003 6:56 pm Post subject: |
|
|
haha!!
it likes php4.32 support input type=text case!!
i remember 4.30 does not support it,can not use count($_POST['hk'])
koo
sorry!!
i made a mistake! |
|
Back to top |
|
|