WesleyA Posted September 9, 2015 Share Posted September 9, 2015 Can someone give an example of a php script that lets a form with checkbox input choose between 2 different pages when it is checked or not. Actually the dilemma is that the action attribute is sending form data to another pages (2 pages) - but dont know what code to use - . So if the checkbox isnt checked a third page should load in the browser. Link to comment Share on other sites More sharing options...
COBOLdinosaur Posted September 9, 2015 Share Posted September 9, 2015 put the code for each page in its own include, and then use the value of the checkbox to include the appropriate code: if (!empty($_POST['mycheckbox'])){ include '../page1.inc';}else{ include '../page2.inc';} Or just resolve the page that that should be loaded client side and alter the action with javascript. Link to comment Share on other sites More sharing options...
WesleyA Posted September 10, 2015 Author Share Posted September 10, 2015 And what should be done with the action attribute in the form element which directs the the data to a new page? Link to comment Share on other sites More sharing options...
dsonesuk Posted September 10, 2015 Share Posted September 10, 2015 So you want the user to have the ability to open two pages in different tabs/windows or both in one page? which the checkbox would be the correct input type to use, OR give the user the ability to select one or the other where input type radio should be used where also the third page could be the default.If you use cobol PHP method i should check if file exits before attempting to include. Link to comment Share on other sites More sharing options...
WesleyA Posted September 10, 2015 Author Share Posted September 10, 2015 (edited) Yeah my idea is that 2 pages are a good solution. I tried to add the code with include but it doesnt open the pages in a new window or new tab which I would rather have. ( I heard of COBOL as a very old programming language as I'm born in the sixties and COBOL is from that period or so, but now I program PHP, as far as I know I only use the most common library of instructions. I now have WAMP installed I dont use tools or API's, dialect etc. at the moment.) Edited September 10, 2015 by WesleyA Link to comment Share on other sites More sharing options...
dsonesuk Posted September 10, 2015 Share Posted September 10, 2015 When i said cobol i was refering to COBOLdinosaur. Yeah my idea is that 2 pages are a good solution.Still does not tell me from previous post what you are looking for? 2 or more page could be use in any of those options mentioned. Link to comment Share on other sites More sharing options...
COBOLdinosaur Posted September 10, 2015 Share Posted September 10, 2015 When i said cobol i was refering to COBOLdinosaur. Its Okay I am actually older than COBOL and I even beat the introduction of ENIAC by a little bit. Link to comment Share on other sites More sharing options...
WesleyA Posted September 11, 2015 Author Share Posted September 11, 2015 When i said cobol i was refering to COBOLdinosaur.Still does not tell me from previous post what you are looking for? 2 or more page could be use in any of those options mentioned. But include makes that the page content is showed on the same page. Link to comment Share on other sites More sharing options...
dsonesuk Posted September 11, 2015 Share Posted September 11, 2015 AaaaarrrggggghhhThe user has the option with two checkboxes to select ALL, i.e BOTH!Is that what you want?IF YESDo you want the user to have the ability to open two pages in DIFFERENT tabs/windows/pages or BOTH in same one page?IF NOthen you should be using radio buttons where only one page can be selected. Link to comment Share on other sites More sharing options...
WesleyA Posted September 11, 2015 Author Share Posted September 11, 2015 (edited) Im looking for a solution to direct the visitor to a page so they can have a message that the checkbox should be checked. Submit action offers the possibility to direct someone to one page. (or am i wrong?) The idea is that the decision whether the checkbox is checked has to be made in advance. If checked it shoud go on using the submit action (if this is the only solution ???) It works like this: the user gets a list of several choices (taken from a list of mysql database tables) and they have to check. Only 1 is allowed to be chosen. You have to choose one (not 2 or 5 but 1) else the parser gives an error and/or nothing will be added to the database. If the checkbox is chosen the user can add records to the table. What I want is actually free and is also a matter of possibilties there are with HTML/PHP (not javascript). So they can be sent to an error_page and the completed page was one option. Maybe its also an option to have it echoed on the same page but it depends on what is possible and how that is done. What is the difference in approach between these 2 different pieces of script? Edited September 11, 2015 by WesleyA Link to comment Share on other sites More sharing options...
WesleyA Posted September 11, 2015 Author Share Posted September 11, 2015 I think using <SELECT> is a better option. <SELECT> gives the opportunity to choose only 1 option and obliges a choice. Link to comment Share on other sites More sharing options...
dsonesuk Posted September 11, 2015 Share Posted September 11, 2015 Like i keep repeating, for one option use radio buttons, you can set a pre checked option for when the user does not select any, or process this using php if no selections are made. Link to comment Share on other sites More sharing options...
WesleyA Posted September 11, 2015 Author Share Posted September 11, 2015 this topic can become closed. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now