haley
haley

Reputation: 1593

php/jquery-mobile: Second page not running validation on two page form

I'm new to php and am trying to make a very simple two page form. Any help or guidance would be very appreciated!

Problem:

Setup:

Live example:

http://www.linplusg.com/page1.html

In IE the Page 2 URL after coming from Page 1 looks to be incorrect: http://www.linplusg.com/page1.html#/page2.php

In FF and Chrome the URL looks fine but I think there's a flicker/refresh happening.

Does something else happen besides just opening the page when doing a POST to a page? Does something value get stored the new fields? Am I doing the form action wrong? Dazed and confused...

Thank you so much for any help or suggestions. I've been searching around for answers all night and my brain feels like jello. It seems like I'm missing something simple?!

Page1 Code

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>
        </title>
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <link rel="stylesheet" href="css/my.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
        </script>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js">
        </script>
        <script>
          $(document).ready(function(){
            $("#initialForm").validate();
            });
        </script>
    </head>
    <body>
        <!-- Home -->
        <div data-role="page" id="page1">
            <div data-role="content">
              <form id="initialForm" method="post" action="page2.php">
                <div data-role="fieldcontain">
                    <fieldset data-role="controlgroup" data-mini="true">
                        <label for="textinput3">
                            Zip Code
                        </label>
                        <input name="zip" id="zip" maxlength=5  value="" type="text" class="required" />
                    </fieldset>
                </div>
                <input type="submit" data-theme="e" value="Submit" />
              </form>  
            </div>
        </div>
    </body>
</html>

Page 2 code

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>
        </title>
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <link rel="stylesheet" href="css/my.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
        </script>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js">
        </script>    
        <script>
          $(document).ready(function(){
            $("#fullForm").validate();
            });
        </script>
    </head>
    <body>
        <!-- Home -->
        <div data-role="page" id="page1">
            <div data-role="content">
              <form id="fullForm" method="get" action="">
                <div data-role="fieldcontain">
                    <fieldset data-role="controlgroup" data-mini="true">
                        <input name="zip" id="zip"  value="<?php echo $_POST["zip"]; ?>" type="" />
                    </fieldset>
                </div>
                <div data-role="fieldcontain">
                    <fieldset data-role="controlgroup" data-mini="true">
                        <label for="textinput3">
                            First Name
                        </label>
                        <input name="first_name" id="first_name" placeholder="" value="" type="text" class="required"/>
                    </fieldset>
                </div>
                <input type="submit" data-theme="e" value="Submit" />
              </form>  
            </div>
        </div>
    </body>
</html>

Upvotes: 1

Views: 743

Answers (3)

Matt Healy
Matt Healy

Reputation: 3

You could preserve the ajax transitions and still have your javascript execute on your second page by moving your script inside the div with the data-role "page".

See this answer here: https://stackoverflow.com/a/6428127/2066267

Upvotes: 0

peterm
peterm

Reputation: 92795

To prevent this you need to specify data-ajax="false" in the form element in page1.

<form id="initialForm" method="post" action="page2.php" data-ajax="false">

see http://jquerymobile.com/test/docs/forms/forms-sample.html for more information.

Upvotes: 1

akirk
akirk

Reputation: 6857

Without the PHP code, I can just guess, but maybe it is because in the second form you have a method="get" instead of method="post", and in PHP you check the $_POST variable?

Upvotes: 0

Related Questions