Forum Moderators: open

Message Too Old, No Replies

Can I get a form to link to a certain page?

         

Squidlips

4:17 am on Aug 8, 2008 (gmt 0)

10+ Year Member



Hi there,

I was wondering if I can get a form to link to a certain page, if a certain number is input into the form.

For example, if a person was to input number ‘1234’ can the form pick this up and navigate to a page, especially for number ‘1234’?

And if they input any other number, I’d like the form to pick up on the fact that its not number ‘1234’ and then navigate to a different page that says ‘number not found’.

I am trying to avoid using a database, as I dont know a lot about them.

Many Thanks for your help

Marc.

Marshall

6:08 am on Aug 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi Squidlips, welcome to WebmasterWorld.

IMHO, your solution would be a javascript with an if statement. This would an onclick event. A real short example would be something like this:

In the submit button -

onclick="checkField()"

In the <head> a script to the effect -
<script type="text/javascript">
function checkField() {
if (document.form.FIELDNAME.value == 1234){
window.location=URL
}
else { window.location=URL
}
}
</script>

Mind you, I am not an expert in writing scripts, but I think you get the idea. I am sure someone else can help. You may want to post your question in the javascript forum. I do know this, you can use multiple 'if' statements within the script so you could do several URL variations.

Marshall

Squidlips

6:35 am on Aug 8, 2008 (gmt 0)

10+ Year Member



Thanks Marshall,

I'l deffo give that a go, and at least I know in which direction to investigate now.

Many Thanks for all the info

Marc.

Marshall

6:44 am on Aug 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You're welcome.

Marshall

rocknbil

6:26 pm on Aug 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another way to approach this is using a dynamic scripting language like perl , PHP, or ASP. No database would be required.

You have this:

<form method="post" action="pagefinder.cgi">
<p><label for="page_num">Enter page number</label>
<input type="text" name="page_num" id="page_num"></p>
<p>Input type="submit" value="Go To Page">
</form>

In pagefinder.cgi (or .php, .asp) the logic is pretty simple:

- Read and parse the input, get the value of page_num
Example: $page = $FORM{'page_num'};

Check if the file exists. If you use extensions,

$page+= '.html';

if (-f "$page") {
Here you either REDIRECT to the page or slurp it up and output it right from the script
}
else {
print "content-type: text/html\n\n";
print "page not found";
(It would be useful here to just print another copy of the searching form so the user can just search again)
}

This makes your process not dependent on Javascript, which makes it more reliable.

Squidlips

2:15 am on Aug 12, 2008 (gmt 0)

10+ Year Member



thanks for that rocknbil ! i'll give that a whirl this weekend.

Ta

Marc