Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default Opening form in DIV

    Hey,

    Im using AJAX to open pages in a div (obv ) but I have a page opened in it with a form in and when I submit the form it doesnt submit in the div but in a new page, how can I stop this?

    Thanks

  2. #2
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Robbie! View Post
    Hey,

    Im using AJAX to open pages in a div (obv ) but I have a page opened in it with a form in and when I submit the form it doesnt submit in the div but in a new page, how can I stop this?

    Thanks
    I had this problem.

    Basically Iszak and Matt coded Js for me to fix it.

    You gotta call a function on form submit and it either requests a php file, my login form for instance, and returns var or w/e. Or just posts form info to file then reloads to submit page.

  3. #3
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    I guess you mean submitting a form via javascript?

    I have created a simple form which will submit via javascript if this is was you require.
    http://www.habbcrazy.net/jack/contacttest.php

    For this, you will have to download prototype and scriptaculous (google them)

    contacttest.php
    HTML Code:
    <head>
    <script type="text/javascript" language="javascript" src="js/prototype.js"></script>
    <script type="text/javascript" language="javascript" src="js/scriptaculous.js"></script>
    
    <script language="javascript" type="text/javascript">
    function submitForm()
    {
        name = document.getElementById("name").value;
        email = document.getElementById("email").value;
        message = document.getElementById("message").value;
    
        $('form-container').innerHTML = '<img src="loading.gif" />';
        
        new Ajax.Request('submit.php',
        {
            parameters: {name: name, email: email, message: message},
            onSuccess: function(transport)
            {
                $('form-container').innerHTML = transport.responseText;
            }
        });
    }
    </script>
    
    </head>
    
    <body>
    <div id="form-container">
        <form id="form" action="javascript:submitForm();" method="post">
            <strong>Name</strong>:<br>
            <input type="text" size="20" id="name" name="name"></input><br>
            <br>
            <strong>Email</strong>:<br>
            <input type="text" size="20" id="email" name="email"></input><br>
            <br>
            <strong>Message</strong>:<br>
            <textarea cols="30" rows="5" id="message" id="message"></textarea><br>
            <br>
            <input type="submit" value="Submit"></input>
        </form>
    </div>
    </body>
    submit.php
    HTML Code:
    <?php
    
    if(isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["message"])) {
        
        $name = $_POST["name"];
        $email = $_POST["email"];
        $message = $_POST["message"];
        
        if($name == "" || $email == "" || $message == "") {
            echo("<p><font color=\"red\">You left a required field blank!</font></p>
                    <form id=\"form\" action=\"javascript:submitForm();\" method=\"post\">
                        <strong>Name</strong>:<br>
                        <input type=\"text\" size=\"20\" id=\"name\" name=\"name\" value=\"$name\"></input><br>
                        <br>
                        <strong>Email</strong>:<br>
                        <input type=\"text\" size=\"20\" id=\"email\" name=\"email\" value=\"$email\"></input><br>
                        <br>
                        <strong>Message</strong>:<br>
                        <textarea cols=\"30\" rows=\"5\" id=\"message\" id=\"message\">$message</textarea><br>
                        <br>
                        <input type=\"submit\" name=\"Submit\"></input>
                    </form></p>");
        } else {
            echo("<p><font color=\"green\">Your message has been sent (Well, not really)</font></p>
                    <p>
                        <strong>Name</strong>: $name<br>
                        <strong>Email</strong>: $email<br>
                        <strong>Message</strong>:<br>
                        $message
                    </p>");
        }
    } else {
        header('Location: contacttest.php');
    }
    
    ?>
    Hope this helps

  4. #4
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    Nice one Jack. You got a cool name too. Security would be in order next time.

  5. #5
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by Jackboy View Post
    Nice one Jack. You got a cool name too. Security would be in order next time.
    Your names cool too

    Yes, I'm really going to add security to an example

  6. #6
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    766
    Tokens
    0

    Default

    Quote Originally Posted by Jack120 View Post
    Your names cool too

    Yes, I'm really going to add security to an example
    You hosted it on habbcrazy so you probably should have.

  7. #7
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default

    Thanks for help guys but I sorted it anyway. +Rep

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •