Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submitting a form and sending a value

Status
Not open for further replies.

mattpont

Programmer
Jan 31, 2003
66
GB
I have a form spread over 10 pages (client wants no scrolling!), this is done in PHP.

I have 10 links at the bottom, which when clicked should take the user to that part of the form AND submit the current form to update the database.

I use the "javascript:document.form1.submit();" code to submit the form when the user clicks on it. But then this obviously runs the PHP update code I've written which by default goes to the next page. i.e if on page 6 it will go to page 7.

What I want to do is when a user is on page 6 and then clicks on the page 3 link, it will submit the form and update the database, and then redirect to page 3, rather than page 7.

Any ideas how I do this? I've been thinking for 2 hours now, and can't get anywhere.
 
just wondering, why would you do it this way? Why not step them through the process?

[conehead]
 
It's because its a form which has been designed so they can go back to at a later date and change anything they've put in.

Therefore they may wish to go to page 2, change something, then go straight to page 7 without going through all the in between pages.

Is there anyway of setting a session in Javascript which I can then read in the PHP code to set the PHP redirect? That was one of the ways I've pondered...
 
One way I would suggest is this:

You have 7 pages, each with a form. you have one main page that handles data processing, we'll call it update.php.

Each page looks like this:


Data: ______
Stuff: _____

P1 - P2 - P3 - P4 - P5 - P6 - P7

And then, in each of the links on the bottom (p2, etc.), you call some JavaScript to set the value of a hidden field, (gotopage = 4) and then submit the form to update.php.

update.php will then update the db with data and redirect you to page 3.

Does this help?

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
I would have each link have button have it's own form and send all buttons to a page that would then submit/update the information - then redirect to the new page...

does that make sense?

[conehead]
 
but then how would you submit the data, if each link was in it's own form?

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Code:
<form action="update.php" name="form1" method="post">
   <input type="hidden" name="redirect" value="1">
</form>

<form action="update.php" name="form2" method="post">
   <input type="hidden" name="redirect" value="2">
</form>

<a href="#" onclick="document.all.form1.submit();">1</a>
<a href="#" onclick="document.all.form2.submit();">2</a>

Make sense? May not be the best way... but it would work...


[conehead]
 
yeah, yeah, yeah... I was not thinking right... *cLFlaVA
way is best... each link would be

<a href="#" onclick="sender('1')">1</a>
<a href="#" onclick="sender('2')">2</a>

and so on...

with a function sender(red) {
document.all.form.hfield.value=red;
document.all.form.submit();
}

with a

<input type="hidden" name="hfield">

in your form somewhere

then on you update page use the hfield value to control the redirect

[conehead]
 
only thing i'd change is the function (for cross-browser compatability):

Code:
function sender(red) {
    document.forms['form_name'].elements['field_name'].value = red;
    document.forms['form_name'].submit();
}

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
no worries, just wanted to give the option in case he's using browsers other than ie

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
TheConeHead's first suggestion sparked an idea in my head. You can put all the pages in one html file and submit them all at once w/o the user needing to jump from page to page. Just encapsulate each pages material in a div and only show one div at a time. Somethign like this:
Code:
<html>
<head>
<script language=javascript>

function changePage(num) {
   for (i = 0; i < 4; i++) {
      document.getElementById("page" + i).style.display = (i == num) ? '' : 'none';
   }
}

</script>
</head>
<body style='text-align:center'>
<form name=blahForm>
<div id=page0>
This is the first page.<br>
<table>
<tr><td><input type=checkbox></td><td>Click for yes</td></tr>
<tr><td><input type=checkbox></td><td>Click for no</td></tr>
</table>
</div>
<div id=page1 style='display:none'>
This is the second page.<br>
<input type=text>Enter something.
</div>
<div id=page2 style='display:none'>
This is the third page.<br>
<input type=button value=What>
<input type=button value=do>
<input type=button value=you>
<input type=button value=think>
<input type=button value=of>
<input type=button value=my>
<input type=button value=buttons>
</div>
<div id=page3 style='display:none'>
This can continue for 10 pages......
</div>
<br><br>
- Page -<br>
<input type=radio name=blahRadio onclick='changePage(0)' checked>1 
<input type=radio name=blahRadio onclick='changePage(1)'>2 
<input type=radio name=blahRadio onclick='changePage(2)'>3 
<input type=radio name=blahRadio onclick='changePage(3)'>4 
</form>
</body>
</html>

-kaht

banghead.gif
 
Which would be a terrible load time if there were large amounts of data / images in the file...

but a viable solution, if you don't care about load time, or your div's are quite small.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top