Click to See Complete Forum and Search --> : [RESOLVED] One Form Button to insert DB record and pass variable


lloydmav
07-21-2008, 11:57 AM
Hi,

Really hope someone can help me with this.

I have a submit button in a form and I would like to get the submit button to do two things.

Firstly I would like to get it to insert a db record. This I have working on its own using the following form code:

<form action="<%=MM_editAction%>" method="POST" name="form1">
<input type="text" name="first_name" id="first_name" tabindex="2" />
<input type="text" name="last_name" id="last_name" tabindex="3" />
<input type="text" name="email" id="email" />
<input type="submit" name="insert" id="insert" value="Continue" />
<input type="hidden" name="MM_insert" value="form1" />
</form>

the <%=MM_editAction%> does the insert record stuff in the asp javascript bit at the beginning.

Secondly I then need to be redirected to another page 'subscriptionpt2.asp', but I need to pass a form variable with it so that I can identify this record again. I have managed to get this working sepertely using the following code:

<div id="mainContent">
<form action="subscriptionpt2.asp" method="post" name="form1">
<input type="text" name="first_name" id="first_name" tabindex="2" />
<input type="text" name="last_name" id="last_name" tabindex="3" />
<input type="text" name="email" id="email" />
<input type="submit" name="insert" id="insert" value="Continue" />
</form>
<!-- end #mainContent -->
</div>

I have both things working fine on their own but how do I combine the two actions so that when I click submit they both happen and I can pick up the email variable in the next page???

Really stuck with this:confused:

Thanks

ray326
07-21-2008, 02:38 PM
Model-View-Controller

The form (view) posts it's input to the controller (the form action). The controller updates the database, sets up the model in the session for the next view (page containing your second code box) and forwards or redirects the browser to that view.

If you know the technologies involved and you thing in those terms then what you're trying to do it pretty trivial stuff.

lloydmav
07-22-2008, 06:02 AM
thanks Ray for the reply. Its a bit crytic though or perhaps just not in terms I understand, or perhaps I've been pulling at my hair for too long to understand but I still don't understand what I need to do.

Two forms. I must have to combine them somehow into one form so they both submit at the same time, unless maybe one form submit is triggered by another. Or do I need to seperatly pass the variable ready for the next page, while the form then justs updates the database and then redirects...??

Not sure where all this should be done in the page either...

Please give me some code example pointers... thanks

lloydmav
07-22-2008, 10:26 AM
okay, so its amazing what a few hours away from it all can do to clear your head.

So it turned out to be a case of setting a seperate variable that could be accessed by the next page.

I added a line of code in the ASP (Javascript) where the insert record variables were being set.
The line of code sets up a session variable ready for the next page.

Session("FirstName") = String(Request("txtFirstName"));

Lloyd

ray326
07-22-2008, 09:58 PM
Bingo.