Search code examples
javascriptphpandroidhtmlintel-xdk

Intel XDK Sharing data between two pages


Okay... so this is my first ever question here in StackOverflow and not really that good in programming beyond near basic html, css and php, so I'll just start with my first and mind boggling question.

I'm currently making an app for my school and am almost done (if my teacher doesn't suddenly decide to make things harder than it already is which he already did like 5 times already this month) but I came to a dead end when my php codes won't run.

My question is how to share data between two pages within a "form" method without a database.

I don't want to store the data given in any way because i'm going to use a "Fake" database with preset requirements inside the code in ifs, ands and elses so that if I can't connect to a database (of which I already found solutions for) because the net may or may not be faulty at the final defense (which will be embarrassing). I have tried searching for it many times for over a week but still no solutions. The tutorials in the XDK forums were practically useless in my question so I'm asking this here.

The form needed a Username and a Password variable in order for it to continue to the next page which will determine if the code entered is equal to a preset username variable and a password variable within the code to activate a button that will allow the user to edit the contents instead of just looking at them.

<form action="php/respo.php" method="post">
    <h3>
    Username:<br>
    <input type="text" name="user" value="username">
    <br><br>
    Password:<br>
    <input type="password" name="passme" value="">
    <br><br>
    <input type="submit" value="Submit">
    </h3>
</form>

The code is the form i'm using with the main css that adapts to the size of the device so that no matter how small or big your frigin device is, it'll adapt to it. The problem is that whenever I press submit to this code:

<p>Welcome <?php echo $_POST["user"]; ?><br></p>
<p>Your Password is: <?php echo $_POST["passme"]; ?></p>

The page just says "Cannot POST /php/respo.php" and if I change the method to get or delete the method thing it pops up a window that saves the php page to XDK/Downloads folder. My reaction was a clasic "What in the frigid ell?". In my mind, I was saying goodbye to my chance at graduating this year.

And in my defense I have never tried to make an app (same with all my classmates) in my entire life. So imagine my face when that popped up the strict standards that shoved itself up the teacher's butt.

I kept trying to figure it out but to no avail because most of the time, the answers to other questions that I tried to piece together were too vague to understand in layman's term. I am not good at java... at all. Almost failed that class too. -_-'

So please... I really need help with this thing. And please explain it thoroughly and not just vaguely like a link or a single word? Coz it still frigin confuses the daylight out of me.


Solution

  • you can use a framework like Ionic, AngulaJS to use their data-bind,

    or if you want a really simple for to do this, here it is mine:

    <form action="none" method="post">
        <h3>
        Username:<br>
        <input type="text" onchange="Data.name = this.value">
        <br><br>
        Password:<br>
        <input type="password" onchange="Data.pass = this.value">
        <br><br>
        <input type="submit" value="Submit" onclick="ok()">
        </h3>
    </form>
    
    <script>
    var Data= {
        name:"",
        pass:""
    }
    function ok(){
        alert("your name: " + Data.name+"\nyour password: "+Data.pass)
    }
    </script>

    or you can use javascript to get the value of the input, then you don't need the var Data, search for document.getElementaryById