Jump to content

0 Not recognised as php required field imput?


Captain Salad

Recommended Posts

Guest footballkid4
You can use:
[code]if ($_REQUEST['email'] == "")
{
     //not supplied
}[/code]

Or
[code]if ( strlen( trim( $_REQUEST['email'] ) ) > 0 )
{
    //supplied
}[/code]
Link to comment
Share on other sites

[!--quoteo(post=358901:date=Mar 27 2006, 09:35 AM:name=annihilate)--][div class=\'quotetop\']QUOTE(annihilate @ Mar 27 2006, 09:35 AM) [snapback]358901[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[a href=\"http://uk2.php.net/empty\" target=\"_blank\"]http://uk2.php.net/empty[/a]

The string '0' is considered empty, so will have to use a different method of validation if you want to allow zeros.
[/quote]

Thanks for your input, I was afraid of that. Any help with the code I would need to add in order to allow 0? I am a total newb to PHP and coding of any sort so any further help will be greatly appreciated.

God bless
Link to comment
Share on other sites

[!--quoteo(post=358904:date=Mar 27 2006, 09:42 AM:name=footballkid4)--][div class=\'quotetop\']QUOTE(footballkid4 @ Mar 27 2006, 09:42 AM) [snapback]358904[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can use:
[code]if ($_REQUEST['email'] == "")
{
     //not supplied
}[/code]

Or
[code]if ( strlen( trim( $_REQUEST['email'] ) ) > 0 )
{
    //supplied
}[/code]
[/quote]


Hi, Thank you for trying to help me, so would this be correct?

$yearsataddress = if ($_REQUEST['yearsataddress'] == "")
{
//not supplied
}
$monthsataddress = $_REQUEST['monthsataddress'] ;
Link to comment
Share on other sites

Try this, substitute the function empty in your script for checkLength
Example use: checkLength($title, 0, 50);
[code]// String length
// Usage:  checkLength(string to check length of, min length, max length)
function checkLength($string, $min, $max)
{
$length = strlen(trim($string));
    if ( ($length < $min) || ($length > $max) )
    {
    return FALSE;
    }
    else
    {
    return TRUE;
    }
}[/code]
Link to comment
Share on other sites

Hi, thanks for you help, sadly I think I am way over my head as I cant get it to work still and not sure wher I should add the code (as I said I am total noob) , is there any chance you could be so kind as to amend the below code so that the $yearsataddress field proceses 0 if entered?

Sorry for all these pleas for help.

God bless

Link to comment
Share on other sites

Put this anywhere on the page, I would put at the top though.
[code]// String length
// Usage:  checkLength(string to check length of, min length, max length)
function checkLength($string, $min, $max)
{
$length = strlen(trim($string));
    if ( ($length < $min) || ($length > $max) )
    {
    return FALSE;
    }
    else
    {
    return TRUE;
    }
}[/code]

Then change this code section:
[code]if (!isset($_REQUEST['email'])) {
header( "Location: http://www.brittalk.com/brittalk/Templates...actUs.htm" );
}
elseif (empty($email) || empty($transfer) || empty($title) || empty($firstname) || empty($lastname) || empty($dob) || empty($currentaddress)[/code]

To this (I would run the checkLength function on all fields)
[code]if (!isset($_REQUEST['email'])) {
header( "Location: http://www.brittalk.com/brittalk/Templates...actUs.htm" );
}
elseif (checkLength($email,1,40) || checkLength($transfer,1,50) )
// etc etc etc[/code]
If you just want it on the yearsataddress field, then change empty($yearsataddress) to checkLength($yearsataddress, 1, 5) or something. The 1 is the min number of digits, and the 5 is the max. Just change those numbers depending on how long or short the field can be.
Link to comment
Share on other sites

Hi, I changed the code to what you suggested but I get an "error missed a field" message for no matter what I type in the fields, have I missed something, see edited code below.

god bless

<?
function checkLength($string, $min, $max)
{
$length = strlen(trim($string));
if ( ($length < $min) || ($length > $max) )
{
return FALSE;
}
else
{
return TRUE;
}
}

$transfer = $_REQUEST['transfer'] ;
$email = $_REQUEST['email'] ;
$existingnumber = $_REQUEST['existingnumber'] ;
$pacnumber = $_REQUEST['pacnumber'] ;
$title = $_REQUEST['title'] ;
$firstname = $_REQUEST['firstname'] ;
$middleinitial = $_REQUEST['middleinitial'] ;
$lastname = $_REQUEST['lastname'] ;
$dob = $_REQUEST['dob'] ;
$currentaddress = $_REQUEST['currentaddress'] ;
$town = $_REQUEST['town'] ;
$postcode = $_REQUEST['postcode'] ;
$residentialstatus = $_REQUEST['residentialstatus'] ;
$yearsataddress = $_REQUEST['yearsataddress'] ;
$monthsataddress = $_REQUEST['monthsataddress'] ;
$previousaddress = $_REQUEST['previousaddress'] ;
$previoustowm = $_REQUEST['previoustown'] ;
$previouspostcode = $_REQUEST['previouspostcode'] ;
$hometel = $_REQUEST['hometel'] ;
$daytimetel = $_REQUEST['daytimetel'] ;
$bankaccountyears = $_REQUEST['bankaccountyears'] ;
$bankaccountmonths = $_REQUEST['bankaccountmonths'] ;
$occupationalstatus = $_REQUEST['occupationalstatus'] ;
$creditcard = isset($_POST['creditcard']) ? $_POST['creditcard'] : 0;
$yearsinjob = $_REQUEST['yearsinjob'] ;
$monthssinjob = $_REQUEST['monthsinjob'] ;
$accountholder = $_REQUEST['accountholder'] ;
$accountnumber = $_REQUEST['accountnumber'] ;
$branchsortcode = $_REQUEST['branchsortcode'] ;
$printnamebank = $_REQUEST['printnamebank'] ;
$datebank = $_REQUEST['datebank'] ;
$termsconditions = $_REQUEST['termsconditions'] ;
$printnameterms = $_REQUEST['printnameterms'] ;
$printdateterms = $_REQUEST['printdateterms'] ;

if (!isset($_REQUEST['email'])) {
header( "Location: [a href=\"http://www.brittalk.com/brittalk/Templates/contactUs.htm"\" target=\"_blank\"]http://www.brittalk.com/brittalk/Templates...actUs.htm"[/a] );
}
elseif (checkLength($email,1,50) || checkLength($transfer,1,50) || checkLength($title,1,50) || checkLength($firstname,1,50) || checkLength($lastname,1,50) || checkLength($dob,1,50) || checkLength($currentaddress,1,50)
|| checkLength($town,1,50) || checkLength($postcode,1,50) || checkLength($residentialstatus,1,50) || checkLength($yearsataddress,1,50) || checkLength($monthsataddress,1,50) || checkLength($hometel,1,50) || checkLength($daytimetel,1,50)
|| checkLength($bankaccountyears,1,50) || checkLength($bankaccountmonths,1,50) || checkLength($occupationalstatus,1,50) || checkLength($monthssinjob,1,50) || checkLength($yearsinjob,1,50) || checkLength($accountholder,1,50)
|| checkLength($accountnumber,1,50) || checkLength($branchsortcode,1,50) || checkLength($printnamebank,1,50) || checkLength($datebank,1,50) || checkLength($termsconditions,1,50) || checkLength($printnameterms,1,50) || checkLength($printdateterms,1,50)) {
Link to comment
Share on other sites

I would change all the || into &&. And if you want to allow some fileds to be left blank, put the min value as 0. I have quickly done a test of whether it works and it works perfectly. This is the little bit of code I tested on.
[code]<?php
function checkLength($string, $min, $max)
{
$length = strlen(trim($string));
    if ( ($length < $min) || ($length > $max) )
    {
    return FALSE;
    }
    else
    {
    return TRUE;
    }
}

$name = trim(strip_tags($_POST['Name'])); // Name
$email = trim($_POST['Email']); // Email
    
if ( checkLength($email, 1, 50) && checkLength($name, 1, 50))
{
echo 'Passed validation';
}
else
{
echo 'Failed';
}

?>
    
    <form name="Contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <table class="padform">
    <tr><td><label for="Name">Name</label></td><td><input name="Name" id="Name" type="text" size="50" maxlength="50" value="<?php if ( isset($_POST['Name']) ) echo trim(strip_tags($_POST['Name'])); ?>" /></td></tr>
    <tr><td><label for="Email">Email</label></td><td><input name="Email" id="Email" type="text" size="50" maxlength="50" value="<?php if ( isset($_POST['Email']) ) echo trim($_POST['Email']); ?>" /></td></tr>
    <tr><td> </td><td align="center"><input name="Submit" type="submit" value="Contact" /></td></tr>
    </table>
    </form>[/code]
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.