This works perfectly well for me. The key thing that makes this work where your code does not is $_POST[‘OPTION1’] - you’ve used $_POST[‘Option1’] in your sample above and that’s not the same thing.
I’ve used the correct format, non capitalized, same as original select name and the second page only picks the 1st value so on page2 of form, the drop downmenu has Option Description 1, Option Description 1a, Option Description 1b, Option Description 1c, it will always pre-populate with Option Description 1 as the selection vs what the user selected on page 1.
Seems to be an issue with the selected=“selected” part.
also all pages are php includes like wp with header.php, navbar,php, content.php,footer.php, I am thinking I should make page2.php a straight html page with all code since it is echoing the user input. or am I mistaken?
Position in the directory structure shouldn’t make any difference - if that was a problem you’d get a 404.
What happens if you insert the echo statements at the top of your second page - what values do you get for the option values? You need to check what the variables contain when they arrive at the second page, then we can see why they’re not working properly in the <select>. Echo them to the screen and exit() straight away and go from there.
at the start of your second page and see what it displays.
That should give whatever values your user selected in the first form displayed on the screen, with nothing else. When I tried it with your code (after I added ‘type=“submit”’ to get a submit button) I get the value from the ‘option value=’ code as you might expect, differing for each value I select.
Can you show your actual code (or the relevant parts of it) rather than just something similar, or is it too big or some other issue? It’s quite hard to debug without seeing exactly your code because the summary you posted is fine. If you’re worried about whether the various includes are confusing matters, comment them out until you see what’s happening.
OK, so the variables aren’t getting from the first page to the second page, they have no values there, so that’s why the second page won’t pre-select the option values, nothing to do with the ‘selected’ part.
What happens if you replace the submit button with a proper ‘input type=“submit”’ instead of using an image? I’m reading things that suggest using an image can cause some changes depending on which browser you use. I was testing with a standard submit button. Change it to that in the first page and see if that helps. If it does, you can use CSS to style the button to have an image.
Well, I don’t know. I’ve taken your code from the first page, changed the form post destination, and posted it into a file on my local wamp server. I’ve removed the extra ‘</select>’ that appears after the state selection, but it worked before that as well.
Obviously I don’t have the CSS or anything, but when I post it to sptest2.php:
<?php
// debug bits, see what the var contents actually are
echo $_POST['State'].'\
';
echo $_POST['Style'].'\
';
echo $_POST['Paint'].'\
';
exit();
?>
I get
AK\
Blue\
Enamel\
But I notice in your sample code above you’re changing the variable names again -
where did $type come from? And later in the same code you echo $Style, $State and $Paint, not $property, $state and $purpose that you used in the start of the page. That’s what I meant about seeing the ‘actual’ code, it’s hard to see what might be wrong if this is just a paraphrased version.
Does it matter that your destination in the first page (“reg-online/send”) is not specifically a .php extension? Will the server treat it as php and process it without the name ending in .php? If you change it and rename to send.php, does that help?
not sure if that will help and this is my first attempt at using 5 separate files to make one page (header, footer, body, navigation, doctype)
these are just php includes files without any html extension on the end when displayed. (like wordpress)
<?php
// Edit the following three lines of code. '$a' adjusts the relative paths of the page. '$current" tells the Nav Bar what the current page is. '$thisPageContent' should match the filename in the includes > 6.content folder.
$a = '../';
$current = 6;
$thisPageContent = 'applications.php';
// Do not change the following line of code. You can go into the '0.seo.php' file to edit SEO content.
include ($a . 'includes/0.seo.php');
// Edit the following three lines of code. You will want to match the variables after the equals sign to the variables in '0.seo.php'.
$thisPageTitle = $applicationsTitle;
$thisPageKeywords = $applicationsKeywords;
$thisPageDescription = $applicationsDescription;
?>
<?php
include ($a . 'includes/0.sitelinks.php');
include ($a . 'includes/1.doctype.php');
?>
<head>
<?php include ($a . 'includes/2.head.php'); ?>
<title><?=$thisPageTitle?></title>
<meta name="keywords" content="<?=$thisPageKeywords?>">
<meta name="description" content="<?=$thisPageDescription?>">
</head>
<body>
<?php
include ($a . 'includes/3.top.php');
include ($a . 'includes/4.navbar.php');
include ($a . 'includes/6.content/' . $thisPageContent );
include ($a . 'includes/7.footer.php');
include ($a . 'includes/8.bottom.php');
?>
</body>
</html>
OK, how would I make this page php? … by changing the bottom area and top?
since it is not saveable in DW as a .php, I am not sure how to go about this.
What I actually meant was that the file name doesn’t end in “.php”, so I wondered how the server would know that it should process the file - perhaps your server processes all files to see if they have php code in them. If I rename my second file to ‘sptest2’ without the .php extension and modify my destination, my wamp server does not process the php and all I get is the code displayed on the screen.
Do the includes work, is the additional content included? I guess it must be if the ‘echo’ statements were working as you said earlier. If the php code in the second file is executed rather than displayed, it can’t be that.
I don’t know, I’m out of ideas. I am not familiar with Dreamweaver, it always concerns me when I hear that you can’t control what filename you use for stuff because of the editor and I’ve steered clear of them because of that kind of thing.
Yes, the file does redirect and I guess it does process it as php since we had values before. I think I’ll have to make the second page a full html page (not separate files being combined) and save as .php although the site we got the idea from does not do that. They are on WP and use gravity forms. So, I can’t understand why this site needs to have a .php extension when that one doesn’t to execute a 2 page form.
I can process the page specifically as a php with this code
Well, maybe it’s the redirection that is causing the problem - does it preserve post variables after redirection.
I can’t see the includes being the issue, because when you put the debugging echo statements in they were at the top of the file before the includes, they were clearly processed as you got the
display, but no variable values.
I have no experience of Wordpress and that kind of site so I can’t offer anything further. It will be interesting to hear if merging all the include files into one makes a difference, please come back and post the results.
yes, that was my thought too as I did merge all includes files into one but no difference, just blank fields when they should be populated.
the form I am trying to emulate is valoancenter dot net a short form with 3 drop down select questions. which sends those same selections to page2.
I’ve seen code dating back to 2006 in this concept but it doesn’t work. Most likely I am doing something wrong.
so, this is what I have
page1 has the form, 3 select menus (actually all pages in the site have it) it redirects to:
page2 (not a php extension file due to php includes) . Although, I did insert the
<?php
session_start();
// other php code here
$_SESSION['One'] = $One;
$_SESSION['Two'] = $Two;
$_SESSION['Three'] = $Three;
?>
at the top before doctype and nothing changed
It is processing as mentioned above but not echoing or posting.