PDA

View Full Version : url change on submit


Jason
03-08-2003, 12:43 AM
For some reason I don't yet understand when the submit button on my form is hit the URL changes when I dont want it to. How do I keep it from changeing.
An example is www.codingforums.com?date=20030307
where the date is specifying todays date. Most of my code is in PHP except my submit button which is a simple
document.writeLn( '<INPUT TYPE="Submit">');

so when the button is clicked the page refreshes and erases all my variables that have to do with the date in the URL. How can I keep it?


Jason

joh6nn
03-08-2003, 05:41 AM
i think i know what the answer is gonna be here, but just to be sure, can you give us some more details. i'm not 100% sure i know what you're talking about.

scroots
03-08-2003, 12:02 PM
it is to do with that the form is submitted to a page do process it, and some of the stuff you see like threadid=15924 is data that is needed for processing.

you can combat this by having a redirect i think.

scroots

Jason
03-10-2003, 10:28 PM
So I don't get it, If I can't get the old URL back then how would I could I set up the redirect link URL to be the old URL? so that it might keep that date=$date on the end?

Jason

joh6nn
03-11-2003, 12:20 AM
still need more info

Jason
03-11-2003, 12:30 AM
ehh, this will be ugly. Ok, well, I dynamically create my URL so its something like www.codingforums.com?date=20030310. The user gets to the page and selects some check boxes and then hits submit so the values of those boxes is then added to my DB. But I need the date for it and the $date variable comes from the URL which gets erased on subit and just returns www.codingforums.com without the ?date=20030310


Jason

joh6nn
03-11-2003, 03:34 AM
you can do that a couple of ways. you can snag the date from the url, or you can use a date object, and you can do that onload, or you can do it on submit.

personally, i suggest forgetting about the date in the url, and i'd there's really only an academic difference with onload vs onsubmit. i'm gonna go with onload.

you need to make a hidden form field, where we're going to store the date, so that when the form gets submitted, the date gets put backinto the url.

<form name="theForm">
<input type="hidden" name="date">

... all the rest of your form stuff here
</form>

your date-getting function would be something like this:

window.onload = function() {
var theDate = new Date();
var year = theDate.getFullYear();
var month = theDate.getMonth() +1;
var day = theDate.getDay();
month = (month < 10) ? "0" + month : month;
day = (day < 10) ? "0" + day : day;
document.theForm.date = "" + year + month + day;
}