Jump to content

!isset Function not working


rick001

Recommended Posts

For some reason the !isset() function doesnt seem to work i cant find out why hope you guys will be able to help

 

Here is the html code for the form where the user enters the data

 


<div id="contact_form">
        
                <h2>On Site SEO Signup Form</h2>
                
                <form method="post" name="contact" action="http://www.techbreeze.in/freeseo.php">

					<label for="uname">Name:</label> <input name="uname" type="text" class="required input_field" id="uname" />
	    <div class="cleaner h10"></div>

					<label for="email">Email:</label> <input type="text" class="validate-email required input_field" name="email" id="email" />
					<div class="cleaner h10"></div>

					<label for="website">Website:</label> <input type="text" class="required input_field" id="website" name="website"/>				
                        <div class="cleaner h10"></div>
                        
                        <label for="ftp">Your FTP Login URL:</label> <input type="text" class="required input_field" id="url" name="url" />
					<div class="cleaner h10"></div>
                        
                        <label for="username">Your FTP Username:</label> <input type="text" class="required input_field" id="user" name="user" />
					<div class="cleaner h10"></div>
                                       
					<label for="password">Your FTP Password:</label> <input type="password" class="required input_field" id="pass" name="pass"/>
					<div class="cleaner h10"></div>				

					<input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l" />
					<input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" />

			</form> 

            </div> 

 

And here is the code for the .php file where the !isset() function is used

 

<?php
     
    // validation expected data exists
    if( !isset($_POST['uname']))
    {
          die ('We are sorry, but all the fields are necessary you cant leave the "Name" field empty!');  
    }
if( !isset($_POST['pass']))
   {
      die ('We are sorry, but all the fields are necessary you cant leave the "Password" field empty!');      
    }
if( !isset($_POST['email']))
   {
        die ('We are sorry, but all the fields are necessary you cant leave the "Email" field empty!');  

   }
   if( !isset($_POST['website']))
    {
          die ('We are sorry, but all the fields are necessary you cant leave the "Website" field empty!');  
    }
if( !isset($_POST['url']))
    {
          die ('We are sorry, but all the fields are necessary you cant leave the "FTP URL" field empty!');  
    }
if( !isset($_POST['user']))
    {
          die ('We are sorry, but all the fields are necessary you cant leave the "Username" field empty!');  
    

 

Thanks in advance

Link to comment
Share on other sites

ok i changed that part to

 

<?php
     
    // validation expected data exists
    if( (!isset($_POST['uname']))|| ( !isset($_POST['pass'])) || (!isset($_POST['email'])) || ( !isset($_POST['website'])) || ( !isset($_POST['url'])) || (!isset($_POST['user'])))
    {
          die ('We are sorry, but all the fields are necessary. Please fill them up carefully!!');  
    }

 

But it still doesnt work

Link to comment
Share on other sites

you are not getting it even using one statement but a shiton of variables does not changing the fact your using TOO MANY.

 

change your logic.

 

if (variable) { pass } else {fail}

 

always check for pass and fail not one or the other.

Link to comment
Share on other sites

isset() is not the best method to use. It is used to test if a variable is in existence withing the scope of the script. It is not used to test whether a variable contains a value. i.e

 

<?php
$x = '';
if(isset($x)) print "x is set";
?>

 

I have cleaned up your code, so replace all those isset() tests at the top with the following:

 

<?php
$required_fields = array('uname','pass','email','website','url','user');
$error = false;
foreach($required_fields as $field) {
if(!strlen(trim($_POST[$field])) && !$_CLEAN[$field]) {
	$error = true;
}
}

if($error) {
die ('We are sorry, but all the fields are necessary. Please fill them up carefully!!');  	
}
?>

 

What you should do is record the fields that are missing the input and print them out so the user knows what to fill in as opposed to just exiting the script with a simple die(). You could do this with:

 

<?php
$required_fields = array('uname' => 'username', 'pass' => 'password', 'email' => 'email', 'website' => 'website','url' => 'url', 'user' => 'user');
$errors = array();
foreach($required_fields as $field => $name) {
if(!strlen(trim($_POST[$field])) && !$_CLEAN[$field]) {
	$errors[] = $name.' is a required field';
}
}

if(count($errors)) {
/*
display errors
*/
print implode('<br />', $errors);
}
else {
/*
process input
*/
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.