Link to home
Start Free TrialLog in
Avatar of Graeme McGilvray
Graeme McGilvrayFlag for Australia

asked on

Request.Form getting multiple values, not just 1

Hello all and thanks in advance

On my main page I have a form which i want people to use to register their email for an event, however i am completely lost on how to get people to register for each event without the page pulling all event numbers

http://www.gptouring.com.au/home.asp

<input type=text name=email placeholder='Email Address'>
<input type=submit name=register value=Register>

Open in new window


Any help is appreciated!
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

That link is broken ...
Avatar of Graeme McGilvray

ASKER

Sorry! please try again
Where is your form? The only form I see is above the table but it is empty.
Also can you explain this sentence
i am completely lost on how to get people to register for each event without the page pulling all event numbers
What do you mean by "page pulling all event numbers"?
Yes there is 1 form for the page, however there is 2 register fields, when it takes both event IDs (not the 1 i want) and passes it to the Register page

sorry i forgot to add in this line of code for each event

<input type=hidden name=eventID value=<%=Next4("event_ID")%>>

Open in new window

you have 4 different form elements with the name of EVENTID, this is why you are getting multiple values for the eventID. you should always have unique names for each form element.

either rename the form elements to be unique or create separate forms for each registration section
Hi Big Monty and thanks for the clarification. the items will be rotating all the time, all having a unique event_ID's

changing to separate forms i prefer not to do, may you help with getting this working with the elements I have?
the NAME attribute of your hidden element needs to be unique, not its value

one idea is to just append the value of the eventID to the name of it:

<input type="hidden" name="eventID<%=eventID%>" value="<%=eventID%> />

then, on your processing page, loop through all of the potential eventIDs that could be on that page, and check for a value:

do while rsEventIDs.EOF
   eventID = rs("eventID")
   if Request("eventID" & eventID) <> "" then
       '-- this was the value selected on the form, process accordingly
   end if
  rs.MoveNext
loop
There are (as I said before) several ways of solving this.

Here is one way
HTML
<form action="submit.asp">
<table>
  <tr>
    <td>
      Event 1<br/>
      <input name="email_event1" type="text" /><br/>
	  <button value="event1" name="action">Submit</button>
    </td>
    <td>
      Event 2<br/>
      <input name="email_event2" type="text" /><br/>
	  <button value="event2" name="action">Submit</button>
    </td>
  </tr>
</table>
</form>

Open in new window

ASP
<%
If Request("action") = "event1" then
   Response.Write "Registering " & Request("email_event1") & " for event 1 "
elseif Request("action") = "event2" then
   Response.Write "Registering " & Request("email_event2") & " for event 2 "
else
	Response.Write "Unrecognised action"
End If
%>

Open in new window


Working sample here
Hi Big Monty, think i have it set right, please check over it as its not going through the loop

<input type=hidden name=eventID"&Next4("event_ID")&" value="&Next4("event_ID")&">

        	Set EventIDs=oConn.Execute("SELECT * FROM events")

            Do While EventIDs.EOF
              eventID=EventIDs("event_ID")
              If Request("eventID"&eventID)<>"" Then
'                do stuff here
              End if
              EventIDs.MoveNext
            Loop

Open in new window


Trying yours now Julian
Julian, how would the ASP go if im using the event_ID of each event as the name, eg

<input type=text name=email"&Next4("event_ID")&" placeholder='Email Address'>
<input type=submit name=register value=Register>

Open in new window

the loop needs to be wherever you're processing the data, not on the same page as your html
Hi Monty, sorry the code of the HTML is actually not on the processing page, i just put it in the same code box

still not selecting anything within the loop unfortunately
ok no problem, just double checking :)

your html markup is wrong, you need to add the  <% %> tags around the recordset:

<input type=hidden name="eventID"<%=Next4("event_ID")%>" value="<%=Next4("event_ID")%>">
No worries, always good to check, just fixed that, still bugging out :/
It is quite simple but don't use <input> rather use button it gives you more options
HTML
    <form action="submit.asp">
      <table class="table">
        <tr>
          <td>
            Event 1<br/>
            <input name="email_event1" type="text" /><br/>
            <button value="event1" name="action">Submit</button>
          </td>
          <td>
            Event 2<br/>
            <input name="email_event2" type="text" /><br/>
            <button value="event2" name="action">Submit</button>
          </td>
        </tr>
      </table>
    </form>

Open in new window

ASP
<%
email = "email_" & Request("action")
Response.Write "Registering " & Request(email) & "For event " & Request("action")
%>

Open in new window

Updated sample
The above code can be modified to remove the "email_" prefix from HTML and ASP - the code will still work as expected.
did you update the URL you gave originally, or are these changes going in a separate environment?

if separate, can you provide the markup from doing a view source on ONE of the hidden elements?
with your ASP Julian, how do i put that into an if statement ?

this is what i currently have:
If Request.Form("register")="Register" Then

Open in new window

its currently on your code Monty
i see for the hidden variables the following:

<input type=hidden name=eventID value=67>

i expect to see

<input type=hidden name=eventID67 value=67>

post your code where you write out those inputs
I just had a look through Chrome Inspection and its showing eventID67 well eventID73 for me :P

User generated image
Response.Write("<font size=4>Tickets for this event are not yet available.<br><br>Provide your email below to be notified of when they are released.<input type=hidden name=eventID"&Next4("event_ID")&" value="&Next4("event_ID")&"><br><br><input type=text name=email placeholder='Email Address'><br><br><input type=submit name=register value=Register></font>")

Open in new window

your code on your processing page is incorrect (my fault, caffeine hasnt hit me yet, it should be:

Do While not EventIDs.EOF
              eventID=EventIDs("event_ID")
              If Request("eventID"&eventID)<>"" Then
'                do stuff here
              End if
              EventIDs.MoveNext
            Loop
Woo! it is looking at the loop now..

however

Microsoft JET Database Engine error '80040e14'

Syntax error (comma) in query expression 'event_code=code_ID AND event_location=location_ID AND event_ID=67, 74'.

yet the eventIDs im looking for are 73 & 75...
I believe the ASP code I posted covers that - you don't need an IF statement.

The event ID is used as the value for the <button> - when you submit the form the action value is sent to the event ID - which can then be used to access the email address.

Here is the button code
<button value="event2" name="action">Submit</button>

Open in new window

Note this is different from the <input type="submit"> - it allows you to specify a Value that is different from the Text for the button. This is useful because it allows us to link the button to the email - which looks like this
<input name="event2" type="text" />

Open in new window

Your ASP code simply has to get the value of the "action" value and use that to access the Request to get the email value
eventid = Request("action")
email = Request(eventid);

Open in new window

Done - nothing else required
Hi Julian, I do need an if statement as the processing is on the same page
i cant debug that without more info, whats the sql statement like?

heading off to a meeting, will try to check back soon
    		If Request.Form("register")="Register" Then
        	Set EventIDs=oConn.Execute("SELECT * FROM events")
            Do While Not EventIDs.EOF
              If Request("eventID"&eventID)<>"" Then
' doing stuff from here              
                Set EventGP=oConn.Execute("SELECT * FROM events,locations,codes WHERE event_code=code_ID AND event_location=location_ID AND event_ID="&Request.Form("eventID"))
          	  	oConnAE.Execute("INSERT INTO enq_pax(pax_fname) VALUES ('Welcome!')")
      					Set NewCust=oConn.Execute("SELECT @@IDENTITY AS New_Cust_ID")
      					CustID=Cstr(NewCust("New_Cust_ID"))
      					Response.Write(CustID)
          	  	oConnAE.Execute("INSERT INTO pax_contacts(pax_ID,pax_email) VALUES("&CustID&",'"&Request.Form("email")&"')")
          	  	oConnAE.Execute("INSERT INTO reg(reg_date,pax_ID,cons_pseudo,event_ID,pax) VALUES('"&Date()&"',"&CustID&",'GPT',"&Request.Form("eventID")&",1)")
' to here          	  	
              End if
              EventIDs.MoveNext
            Loop

Open in new window

Then the process is simply checking if action is empty.

if Request("action") <> "" then
    'process your request here
end if

Open in new window

Hi Julian and thanks for that this is what the output is:

Registering For event event73

need to separate the 73 so i can put that into an SQL statement
Julians solution is essentially as the one I proposed, except for storing the value of eventID in the hidden field, you're putting it in the button value.

try this code, cleaned up a bit as well as it makes sure to avoid sql injection (you should NEVER build a sql statement and append a value to it without checking it first):

If Request.Form("register")="Register" Then
        	Set EventIDs=oConn.Execute("SELECT * FROM events")
            Do While Not EventIDs.EOF
              eventID = EventIDs("event_ID")
              eID = Request("eventID"&eventID)<>""
              If eID <>"" and isNumeric( eID ) Then
                 ' doing stuff from here              
                 Set EventGP=oConn.Execute("SELECT * FROM events,locations,codes WHERE event_code=code_ID AND event_location=location_ID AND event_ID="&eID
          	  	oConnAE.Execute("INSERT INTO enq_pax(pax_fname) VALUES ('Welcome!')")
      					Set NewCust=oConn.Execute("SELECT @@IDENTITY AS New_Cust_ID")
      					CustID=Cstr(NewCust("New_Cust_ID"))
      					Response.Write(CustID)
          	  	oConnAE.Execute("INSERT INTO pax_contacts(pax_ID,pax_email) VALUES("&CustID&",'"&eID&"')")
          	  	oConnAE.Execute("INSERT INTO reg(reg_date,pax_ID,cons_pseudo,event_ID,pax) VALUES('"&Date()&"',"&CustID&",'GPT',"&eID&",1)")
' to here          	  	
              End if
              EventIDs.MoveNext
            Loop

Open in new window

Two solutions.

1. Create a hidden input for the event id and use a prefix to name it
<input type="hidden" name="id_event73" value="73" />

In the ASP page you can access this like this
action = Request("action")
Request("id_" & action);

Open in new window


2. You can split out the id from your value like this
id = Mid(Request("action"), 6)

Open in new window


I have updated the sample to demonstrate both methods.
Julians solution is essentially as the one I proposed, except for storing the value of eventID in the hidden field, you're putting it in the button value.

... yes because the button is always the action so you always know what button was clicked - this is the main advantage of using the <button> over the <input type="submit"> - it gives greater flexibility in processing the variables server side.
that's not what's happening here though, the problem is that the OP had inputs of the same name throughout the form, causing multiple values to be posted.  the solution is to make those fields unique (by adding the eventID onto the name of the input), then check for those IDs on the processing page.

using a button versus an input doesn't really solve the problem...
I was going by this post
how would the ASP go if im using the event_ID of each event as the name, eg
Which implies that the uniqueness had been addressed.
Hey guys, sorry had a few xmas parties that needed attending

Appreciate the help you have been give. been trying your code today

Monty, with your code, this is the outcome:

ADODB.Field error '80020009'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/home.asp, line 0

Julian, unfortunately I am completely lost with yours. i don't know what goes where and don't understand it the ASP you are using, Monty's is the same as everything else that I have done.
Based on your original question (as I understood it) you where looking for a solution to the problem where you where submitting a form with one of the email address fields filled in and not knowing which event the user was signing up for - is this correct?
No. When it was passing the event_ID field, it was passing all that were being able to be registered for on the page, therefore the SQL insert was not working, trying to insert multiple values.

I use these forums not just has a solution to a problem, but to learn and reuse the code that is familiar and similar to mine too. Yours its very alien to me, never seen it before (sorry i only know the ASP I have learnt)
No. When it was passing the event_ID field, it was passing all that were being able to be registered for on the page, therefore the SQL insert was not working, trying to insert multiple values.
Slightly different wording but still the same as I understand it.
On the receive side you receive all hidden ID's and you only want the one for the event that was selected - correct?

This is where the use of the <button> comes in. You can have multiple buttons on the same page with the same name but with different values
<button name="action" value="event101">Submit</button>
<button name="action" value="event201">Submit</button>
<button name="action" value="event507">Submit</button>

Open in new window


When a button is pressed it results in ONE action variable being posted to the server - set to the value of whichever button was pressed. With this method you don't need hidden variables to store the event id - just store it in the value of the Button. To find out the eventID you simply look at the value of Request("action").

That was the gist of my posts - is it on track?
yes, however when it pulls across how can it separate event and 101 from event101??  the 101 is what i need. dont forget there is over 100 events that it could choose from
Two answers

1. Put the event value in the button raw
<button name="action" value="101">Submit</button>
<button name="action" value="201">Submit</button>
<button name="action" value="507">Submit</button>

Open in new window

2. Split out what you want with the Mid function
id = Mid(Request("action"), 6)

Open in new window

My preference would be 1 - but in case you have to prefix your event with a string then 2 is how you would extract it.
so:
<button name="action" value=<%=Next4("event_ID")%>>Submit</button>

Open in new window

?
If that is how you are accessing your event_ID's then yes.
and this for the email input?

<input type=text name=email"&Next4("event_ID")&" placeholder='Email Address'>

Open in new window

eventid = Request("action")
email = Request("email" & eventid)

Open in new window

cheers for that, but it doesnt answer my question above :P
as a test, try commenting out this line:

CustID=Cstr(NewCust("New_Cust_ID"))

if that gets rid of the error, try changing it to:

CustID=Cstr(NewCust(0))
I have just tested to see what 'eID' is, and comes up as FALSE and repeats for every event in my system, this is where the issue is i believe, as we need a number
cheers for that, but it doesnt answer my question above :P
My response was to indicate how to access the email value if you coded it as per your previous post.

We seem to be running two separate threads here so will leave you in the capable hands of Big Monty.
change

eID = Request("eventID"&eventID)<>""

to

eID = Request("event"&eventID)
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'EventGP'

/home.asp, line 184

the line 184 is where it wants to retrieve EventGP data from the SQL, however i dont think its getting as far as the SQL now
it IS getting that far, if that's what line 184 is.

I don't know for sure, as I can't see your code and you're not giving me anything to look at...

if you do a Response.Write of the sql building EventGP and run it directly in your database, what happens?
If Request.Form("register")="Register" Then
       	Set EventIDs=oConn.Execute("SELECT * FROM events")
            Do Until EventIDs.EOF
              eventID = EventIDs("event_ID")
              eID = Request("eventID"&eventID)
              If eID <>"" and isNumeric( eID ) Then
                Response.Write(eID)
                Set EventGP=oConn.Execute("SELECT * FROM events,locations,codes WHERE event_code=code_ID AND event_location=location_ID AND event_ID="&eID)
  '          	 	oConnAE.Execute("INSERT INTO enq_pax(pax_fname,pax_sname) VALUES('Welcome!','Grand Prix Fan')")
  '  			Set NewCust=oConnAE.Execute("SELECT @@IDENTITY AS New_Cust_ID")
  '      		CustID=Cstr(NewCust("New_Cust_ID"))
  '      		Response.Write(CustID)
  '          		oConnAE.Execute("INSERT INTO pax_contacts(pax_ID,pax_email) VALUES("&CustID&",'"&eID&"')")
  '          		oConnAE.Execute("INSERT INTO reg(reg_date,pax_ID,cons_pseudo,event_ID,pax) VALUES('"&Date()&"',"&CustID&",'GPT',"&eID&",1)")
              End if
              EventIDs.MoveNext
            Loop
%>
	<td width=240 height=400 align=center valign=top rowspan=3><a href=?event=<%=eID%>><img src=images/location-<%=EventGP("location_ID")%>.jpg title='<%=EventGP("event_name")%>'></a><br><br>

Open in new window

I have commented out the lines that are not needed for testing this, the last line of code is 184

The EventGP SQL runs perfect :)
you didnt answer my question...
Sorry, i edited the response too late :/

The EventGP SQL runs perfect :)
try eliminating each reference to an EventGP field, one by one, and see if you can figure out which reference is causing the issue
also, you ARE getting records back when you run the sql, correct?
When I run the SQL with an EventID I am getting the record for the EventID

I have put in some response writes to see what is coming through etc.

Response.Write(Request(eventID))

Open in new window


Directly underneath the If Statement, nothing comes through.
you would need to do:

Response.Write Request("eventID"&eventID)

because your form fields have "event" as a pre-fix

but we already know that part is working, as it's building a sql statement and returning a record

what I was saying was to eliminate each reference to EventGP, on line 184, one by one to see which field is causing the issue
I have just replaced my Response.Write with yours, still the same

http://www.gptouring.com.au/home.asp < check it here if you like

commented out the EventGP line 184, it just stopped at the next line asking for more EventGP fields (i have reinstated this so you can test)
SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'EventGP'

/home.asp, line 184 (same line)

this error is actually in the link, looking at the link, eID is the part that isnt coming through <a href=?event=<%=eID%>>

I have updated the live code for you to test
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes you do

make sure you get a record back with that sql
ok, done that, now Response.Writing both EventIDs 73 & 75

have updated live code
looks like everything is working, no?
well it is pulling through both eIDs, not only 1 as i wanted and still to pull over the email address corresponding to the eID
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
an interesting output :P

have updated the live code for you to see the strangeness
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Monty, just replaced the code with the suggested.

its back to where we started, doesnt give a eID
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Monty, have just updated the form code, still the same output
double check again, I see only one sql statement being generated, which is what we want
oh sorry, didnt know we were going for that, sorry
take out all of the debugging statements and you should see only one record being saved
oh fantastic! :) nice work!
can you figure out the email part using the same approach? you'll need to give it a unique name by appending the eventID to it, then read it in the same manner as the event field when doing the processing
I will give it ago now, be back in a bit to plug your brain if need be :)

Thanks again!
I am ballsing this up completely, can't think straight tonight, am going to bed and going to try again tomorrow morning
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fantastic Monty! Works well, however... I have noticed if you sign up for 1 event and then another, it loops into itself..

User generated image
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Big Cheers to BigMonty for the long winded help! :)