Page 1 of 1
Need Help with Forms
Posted: Fri Jun 13, 2008 3:44 pm
by Sepsis2x
I'm fairly new to PHP. What I'm looking to do is having a list of check box options on a page, with a submit button at the bottom. When they click the submit button, I want them to be taken to a new page. The page that the submit button would change depending on what choices they select. I hope that makes sense. Is there any way to do this?
Re: Need Help with Forms
Posted: Fri Jun 13, 2008 7:41 pm
by califdon
Sepsis2x wrote:I'm fairly new to PHP. What I'm looking to do is having a list of check box options on a page, with a submit button at the bottom. When they click the submit button, I want them to be taken to a new page. The page that the submit button would change depending on what choices they select. I hope that makes sense. Is there any way to do this?
What you described is client side--that is, you want something to happen after the page has been sent to the browser and the user does something. But PHP is server side scripting--that is, it is all processed
before the page is sent to the browser, so it can't possibly do anything based on what the user does. What you want is Javascript coding, which is client side.
[
Added:] Well, now that I re-read your question, I should modify what I just said: it is possible to send form variables back to
another PHP script that would redirect yet another page to be sent to the browser, depending on what had been checked. But ordinarily there would be no reason to do that. It can all be done in client side scripting.
Re: Need Help with Forms
Posted: Fri Jun 13, 2008 8:37 pm
by hansford
here's a basic example.
------------------------
Code: Select all
<html>
<body>
<form name='form1' action="" method="post">
check a box to go to that page:<br>
1)<input type='checkbox' name='one' value='1'/><br>
2)<input type='checkbox' name='two' value='2'/><br>
3)<input type='checkbox' name='three' value='3'/><br>
<input type='button' name='but1' value='submit' onclick='getpage();'/>
</form>
<script language='javascript'>
function getpage(){
if(document.form1.one.checked){
document.form1.action='http://www.purple.com';
document.form1.submit();
}
if(document.form1.two.checked){
document.form1.action='http://www.msn.com';
document.form1.submit();
}
if(document.form1.three.checked){
document.form1.action='http://www.cnn.com';
document.form1.submit();
}
}
</script>
</body>
</html>