Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 1st, 2004, 03:39 AM
Authorized User
 
Join Date: Oct 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default reposting data from form

Hi.

I am using a very simple Access database to display a list of names and addresses. Using a series of checkboxes i can select 1 or more names for deletion. On clicking the delete form button it sends the checked names to delete.asp.

each record has the following header.

MemberId, Forename, Surname.

Each of these headings uses a link to reload the page but using a querystring depending on the header . i.e

<a href="delete.asp?member_id">

i can then use this to set the "order by" clause in my sql. I can then redisplay my grid sorted accordingly.

However, when i reload the page using the above href. the form data originally posted is lost. How can i retain it ?

do i have to use session variables here ? if so how do these work? is there a better way of doing this ?

cheers

dave

 
Old October 1st, 2004, 03:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You don't need sessions to do this, just write the posted data back into the value attribute of each form element.

For example:
<input type="text" name="Forename" value="<%=Request.Form("Forename")%>">
 
Old October 1st, 2004, 04:10 AM
Authorized User
 
Join Date: Oct 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that was my whole point of this post. When i click on the link

delete.asp?memberid

the first thing in my code is :

response.write request.form

this returns nothing. as there has been no posted data to this form.

 
Old October 1st, 2004, 04:43 AM
Authorized User
 
Join Date: Oct 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

perhaps i`m not explaining myself too well here :

lets say i have details.asp which contains a form, this form posts information to delete.asp :

for sake of this question .. delete.asp contains.

<% response.write request.form %>
<a href="delete.asp?xxxxxxxx> click me to reload page</a>


ok, so the first time delete.asp is loaded, from details.asp, i can see the posted information, as soon as i click on the above link .. delete.asp is reloaded but the posted form data is lost.


 
Old October 1st, 2004, 05:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I see what you're saying. Sorry, I was assuming you had a single page posting back to itself.

Your choices are to either:
1. save the values in session vars in delete.asp
2. get delete.asp to re-post the values to itself, thus avoiding session vars.

I guess 1. is simpler, you just add code like this at the top of delete.asp
If Request.Form.Count > 0 Then
    Session("Forename") = Request.Form("Forename")
    ....
End If

then, further down the page when you want to display the values back, you just use Response.Write Session("Forename") (or the shorthand <%=Session("Forename")%>).

When the page is reloaded to re-sort the grid the session vars will still be there.

Option 2 is a bit more work. You will need to get delete.asp to post data back to itself, so you'll need a form on delete.asp containing hidden fields to store all the values, for example
<form action="delete.asp" method="POST" name="frmSave" id="frmSave">
  <input type="hidden" name="Forename" id="Forename" value="<%=Request.Form("Forename")%>">
  ...

That's no big deal, but the other thing you'll have to do is change your sorting hyperlinks so that they post the form. Easiest way is to use some client-side javascript. You'll also have to add another hidden field to the form to hold the column to be sorted. Your js would look something like this:
function postdata(sSortBy)
{
  document.frmSave.SortBy = sSortBy;
  document.frmSave.submit();
}

and your hyperlink would change to something like this:
<a href="#" onclick="postdata('member_id');">MemeberID</a>

hth
Phil
 
Old October 1st, 2004, 05:09 AM
Authorized User
 
Join Date: Oct 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

excellent, cheers phil

i`ve not used session stuff before .. are there any disadvantages to it ? how long does the session last ?

 
Old October 1st, 2004, 06:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Don't ask me I'm biased.. I think session vars suck and I never use them.
 
Old October 1st, 2004, 08:04 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

HI,
    Why to go for a session variables? Whenever you are clicking delete button submit to the same page with some querystring .With the help of query you can execute delete code at the top .Aftere deleting records normaaly it willl display rcords. While displaying use
value=Request.form("elementName").
YOu can get all those values, because you are submitting the form.
Thanks
suresh

 
Old October 1st, 2004, 08:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Dave,

Assuming the same code that you posted in one of your posts, you should be able to get that work as shown below.

Suppose by saying Details.asp submits to delete.asp, does that use FORM submission or the value comes as Querystring to delete.asp is the question.

I assume you are doing a FORM submission by the code you mentioned in your example for delete.asp
Code:
<% response.write request.form %>
<a href="delete.asp?xxxxxxxx> click me to reload page</a>
I also assume that your details.asp contains a form field by name "member_id"

Then you need to generalise the REQUEST to take it from any of FORM/Querystring in this case. So your delete.asp code would change as
Code:
<% member_id = request("member_id")%>
<a href="delete.asp?member_id=<%=member_id%>"> click me to reload page</a>
This should solve your problem there.

When you say request.form("member_id"), you are limiting yourselves to get value from FORM posted value from details.asp, instead if you use request("member_id"), this generalizes the request, thus by always holding something that you pass either with form post or as querystring. But make sure that you use the same variable name as that of the one you are requesting. That is the trick here.;)

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 1st, 2004, 09:38 AM
Authorized User
 
Join Date: Oct 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmmmmm - nice try, but i don`t think that will work for me.

you are correct : i am doing a form submission.

the form submission contains a list of member_id values based on which check boxes were selected.

in my delete.asp i do the following :


if request.form("UPDATE")="Update" then
    v_command="MyLeague"
end if

if request.form("DELETE")="Delete" then
    v_command="DeleteM"
end if


sqlstring= "select * from member_details where member_id in("
item_counter = 1
For Each Item In Request.Form(v_command)
    if item_counter =1 then
        itemString = itemString + item
        else
            itemString = itemString + "," & item
    end if
    item_counter = item_counter +1
next
sqlstring=sqlstring + itemString + ") order by member_id"
response.write sqlstring
response.write "<br><br>"
set rsConfig = my_Conn.Execute (sqlstring)



this generates my SQL to query the database.


then to display my grid : i use :



WHILE NOT rsConfig.EOF
%>

<TR>
<TD align="middle" class="boldtable"><a href="select_member.asp?<%=rsConfig("Member_ID")%> "> <%=rsConfig("Member_ID")%> </a></TD>
<TD align="middle"><%=rsConfig("Forename")%></TD>
<TD align="middle"><%=rsConfig("Surname")%></TD>
<TD align="middle"><%=rsConfig("Home_Number")%></TD>
<TD align="middle"><%=rsConfig("Mobile_Number")%></TD>
</TR>

<%
rsConfig.MoveNext
WEND




i`m going to use Phils suggestions, thanks for your help guys.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Data Problem darrenb Access 2 May 2nd, 2007 12:13 PM
Query data in form Vince_421 Access 2 February 1st, 2007 10:45 AM
Saving data using form misskaos Classic ASP Basics 3 October 27th, 2006 03:16 PM
FORM data not valid js_pandey Beginning PHP 2 June 3rd, 2005 06:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.