SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form not working

    Why does the following code not work:
    Code:
    <?php
    	print_r($_POST);
    	if( isset($_POST['logon']) or isset($_POST['register']) )
    	{
    		echo "Do I get here";
    		if( isset($_POST['fname']) )
    		{
    			echo 'Register';
    		}
    		else
    		{
    			echo 'log on';
    		}
    	}
    	else
    	{
    ?>
    <fieldset>
    <legend>Log On</legend>
    	<form action="<?=INDEX . "?" . LOG_ON; ?>" method="post" enctype="text/plain">
    	<p>If you have already registered enter your log on details.</p>
    		<ul>	
    		<li><label for="user">User Name:</label><input type="text" name="user" /></li>
    		<li><label for="pwd">Password:</label><input type="password" name="pwd" /></li>	
    		<div class="ralign"><button type="submit" name="logon">Log On</button></div>
    		</ul>
    	</form>
    </fieldset>
    <p/>
    <fieldset>
    <legend>Register</legend>
    <form action="<?=INDEX . "?" . LOG_ON; ?>" method="post" enctype="text/plain">
    	<p>If you are not registered you need to enter you details below. All fields are required</p>
    	<ul><li><label for="fname">Forename:</label><input type="text" name="fname" /></li>
    	<li><label for="sname">Surname:</label><input type="text" name="sname" /></li>
    	<li><label for="user">User Name:</label><input type="text" name="user" /></li>
    	<li><label for="pwd">Password:</label><input type="password" name="pwd" /></li>
    	<li><label for="email">E-mail:</label><input type="text" name="email" /></li>
    	<div class="ralign"><button type="submit" name="register">Register</button></div></ul>
    </form>
    </fieldset>
    <?php } ?>
    As far as I am aware the name of the submit buttons is what I should be testing for to see if the form has been submitted. I also tried the code from php.net which looks like
    Code:
    (isset($_POST['action']) && $_POST['action'] == 'submitted')
    Basically I am never passing the first condition. Can anyone tell me why? The print_r function always prints Array() which, I think, means nothing is getting set.

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I think it's the enctype="text/plain" that you set. Remove that and try again.
    Saul

  3. #3
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent thank you very much that now works perfectly. Could you take the time to explain why please.

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    php expects application/x-www-form-urlencoded, which is used by default if no enctype is specified or multipart/form-data if you are uploading files.
    Saul

  5. #5
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    php expects application/x-www-form-urlencoded, which is used by default if no enctype is specified or multipart/form-data if you are uploading files.
    Thank you that info will be useful.


Bookmarks

Posting Permissions

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