1

I've been going insane the past 3 hours with this issue. I had this completely working.....and it actually still is, but on another page. The only issue is that on a different page it stops working. Here is the basic run down:

  1. User visit page, clicks on button, JavaScript ModalBox opens up.
  2. In the modal box is a form, which the user fills out and hits Send.
  3. The form action is itself so it returns and checks if isset() is true on the submit button.

This is the issue it seems. I got this working on another script, but it's over 5 pages long so here is the small script that I just can't for the life of me get to work:

<?php session_start(); ?> <html> <head> <?php if (isset($_GET['initForm'])){ echo 'Complete'; } ?> </head> <body> <?php echo ' <div style="padding:0;margin:0;float:left;height:120px;width:100%;"> <div align="center" width="50%" style="padding-top:2px;"><img src="images/step1.png"></div> <div align="center" width="50%" style="font-face:Arial; font-size:14px;padding-top:4px;">Which package are you interested in?</div> <div align="center" width="50%" style="font-face:Arial; font-size:14px;padding-top:6px;"> <FORM action="test.php" name="initForm" id="initForm" onsubmit="return false;"> <select name="packageName"> <option value="Weekend">Weekend - 4 Days/3 Nights</option> <option value="Weekday">Weekday - 5 Days/4 Nights</option> </select> </div> <div align="center" width="50%" style="font-face:Arial; font-size:14px;padding-top:6px;"> <input Type = "Submit" name="initForm" Value ="Send" onclick="Modalbox.show(\'test.php\', {title: \'Vacation Booking\', width: 600, params:Form.serialize(\'initForm\')}); return false;"> </FORM> </div> </div>'; ?> </body> </html> 

-----FIXED------Solution below:-------

^The tag had to be placed on the outermost part of the html and now I can access all the elements of the $_Get array, including the submit button. Can anyone explain why this is so picky? I want my 3 hours back. Well at least I'll hopefully never make a mistake like this again.

4
  • Why the giant echo statement? There's not even any variable interpolation Commented Aug 1, 2011 at 23:33
  • @Phil - My guess is that it was adapted from another script and that's a remnant. I would remove it, of course, and just use plain HTML. Commented Aug 1, 2011 at 23:35
  • 1
    you are echoing out the success message in the head tag. probably not affecting much, but nothing in the head tag should be something that you want people to see. Commented Aug 1, 2011 at 23:40
  • I was just testing successful submission. Commented Aug 1, 2011 at 23:48

2 Answers 2

1

Forms are usually submitted via POST, but you are checking $_GET. Are you doing an AJAX request and sending the data via GET? If not, you should check:

if (isset($_POST['initForm'])){ ... 
Sign up to request clarification or add additional context in comments.

2 Comments

I actually literally JUST figured it out. This is easily one of the strangest things I've ever seen. First of all, yes I believe it's an AJAX request, that's the serialize form part. Now, here was the problem all along: The <FORM> tag had to be placed outside the divs. Really strange.
Doesn't the FORM element default to GET if the method is not specified?
0

I would do:

if (isset($_GET['initForm']) && $_GET['initForm'] == 'Send'){ 

Also, I would also probably specify the method in the form element and use POST instead of GET, due to it's intransigence.

Also, why are you outputting echo 'Complete'; in the head block? This is not right. It should be in the body element (which may also be part of the problem).

5 Comments

It echoes complete now. It is the head block, but since the test.php is included into a modal box of another page in the body tag I guess it works. To reiterate, it was the <FORM> tag being too nested in the html?
I literally just moved the <FORM> and </FORM> tags on the outside of all the divs and now all the elements are submitted and can be retrieved by the $_GET array.
Oh, I see. I didn't notice your markup wasn't properly nested. If you don't nest it properly, the browser will guess what the proper nesting should be (it's called Quirks Mode), and in this case apparently it forced your form to close early, before the input, I supposed.
That's absolutely crazy, I didn't even realize HTML was so stingy. I always thought PHP was cruel. Thanks for all the help.
It's for your benefit (I'm not being facetious, either). I would suggest using a specific DOCTYPE and maybe trying your hand at XHTML Strict Mode so you can get use to proper nesting (although HTML 4.1 or XHTML Transitional are more useful). Also, look into the HTML Tidy add-on for Firefox, which can give you a conformance report rather easily.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.