Click to See Complete Forum and Search --> : collecting data from text fields, putting into column within db table


bradkenyon
04-23-2008, 12:59 PM
i have a form like this:


<form>
<input type="text" name="absentee[]" size="30">
<input type="text" name="absentee[]" size="30">
<input type="text" name="absentee[]" size="30">
<input type="text" name="absentee[]" size="30">
</form>

and i want to collect all data in each field, and bunch together into one string, then enter it into a db table field.

right now i need to know how to bunch everything into a string, i'll separate by colons, so...

data1:data2:data3

also, since i am thinking about this, i need to consider that the person not fill in all the fields, maybe just 2 out of 4 of them, so i want to be sure it doesn't data1:data2:::, maybe we could put something like data1:data2:&nbsp;:nbsp;

what do you think? maybe the &nbsp; in place of an empty field may not be good since i'll want to pull the information back into the input fields on the update function.

thanks,
brad

p.s. new to asp.

bradkenyon
04-23-2008, 02:22 PM
i have done this before, but it was in php for multiple check boxes.

$absentee = $_REQUEST['absentee'];
if (is_array($absentee))
{

for ($i=0;$i<count($absentee);$i++)
{
$content = $content . "$absentee[$i] ";
}
}

sstalder
04-23-2008, 02:41 PM
In ASP (untested):

<%
For Each obj in Request.Form("absentee")
Response.Write Request.Form("absentee")(obj)
Next
%>

I think that might work, but not 100% positive as I haven't used ASP for years.

bradkenyon
04-23-2008, 04:12 PM
In ASP (untested):

<%
For Each obj in Request.Form("absentee")
Response.Write Request.Form("absentee")(obj)
Next
%>

I think that might work, but not 100% positive as I haven't used ASP for years.

no dice on that one. thanks though.

sstalder
04-23-2008, 04:38 PM
What about:

<form>
<input type="text" name="absentee" size="30">
<input type="text" name="absentee" size="30">
<input type="text" name="absentee" size="30">
<input type="text" name="absentee" size="30">
</form>

<%
For X = 0 To UBound(Request.Form("absentee"))
Response.Write Request.Form("absentee")(X)
Next
%>

bradkenyon
04-24-2008, 09:15 AM
this is what i have, the problem i have is, i want the data split up by colons, which i can do w/ this code, but it gives a space after the colon, before the start of the new data.

i'd like the data to be like this...

result1:result2:result3:result4:

if there is a field that was not filled out then, i guess like this as well...

result1:result2:result3::

that would the best way so when i pull it back out of the db, then i can push each value back into the input type text fields when i do my update function?

so to sum it up, i right now it grabs the results like this...

result1: result2: result3: result4:

and i want it like this...

result1:result2:result3:result4:

<script type="text/javascript">
function addInput()
{
var x = document.getElementById("inputs");
x.innerHTML += "<input type=\"text\" name=\"absenteee\" size=\"30\"/><br>";
}
</script>
<h1>Faculty/Staff Absentees</h1>

<%
if (Request.Form("formaction") = "process") Then
'Response.Write(Request.Form("absentee"))

Dim mode,mode_a,i
mode=Request("absenteee")

mode_a=split(mode,",")

For i=LBound(mode_a) to UBound(mode_a)
Response.Write mode_a(i) + ":"
Next

else %>
<form name="myvar" method="post" action="<%Request.ServerVariables("SCRIPT_NAME")%>">

<input type="hidden" name="formaction" value="process">
Date: <input type="text" name="date" size="30" value="<%=FormatDateTime(date(),vblongdate)%>">
<p>Fill in names here: <small><input type="button" value="+" onmousedown="addInput();" />(click for more fields)</small></p>

<%
for i = 1 to 5
Response.Write "<input type=""text"" name=""absenteee"" size=""30""><br>"
next
%>
<div id="inputs"></div>
</p>

<p><input type="Submit" value="Submit" name="Submit"></p>
</form>
<%
end if
%>

sstalder
04-24-2008, 09:24 AM
What happens if you make this adjustment:

For i=LBound(mode_a) to UBound(mode_a)
Response.Write Trim(mode_a(i) & ":")
Next

bradkenyon
04-24-2008, 09:38 AM
works, thanks.

i'll probably have some questions about exploding them out of the database, separating them by the colons to plug into the value's of each input box...

<input type="text" name="absentee" value="value between the colons go here">