Click to See Complete Forum and Search --> : Blank Fields


k0r54
08-13-2004, 09:22 PM
Hi, i have the following code


function filled_out($form_vars)
{
if(isset($_POST['submit']))
{
foreach ($form_vars as $key => $value)
{
if(!strstr($key, 'OPT_'))
{
if ($value == '')
return false;
}
}
return true;
}
}


What this should do is check that every variable has a value except the ones that there names start with OPT_ (i.e OPT_type or OPT_middlename)

I use this to check all of the fields and it works fine


function filled_out($form_vars)
{
// test that each variable has a value
foreach ($form_vars as $key => $value)
{
if (!isset($key) || ($value == ''))
return false;
}
return true;
}



but unfortunatly i have some option fields. If some1 could help me that would be great.

Thanks Adam

s33n
08-14-2004, 05:42 AM
hey, ive got a similar problem to that, help please!!

96turnerri
08-14-2004, 06:47 AM
function filled_out($form_vars)
{
if(isset($_POST['submit']))
{
foreach ($form_vars as $key => $value)
{
if(!strstr($key, 'OPT_'))
{
if ($value == '')
return false;
}
}
return true;
}
}


you are using strstr() which wont work try this


function filled_out($form_vars)
{
if(isset($_POST['submit']))
{
foreach ($form_vars as $key => $value)
{
if(substr($key, 0, 4) != "OPT_")
{
if ($value == '')
return false;
}
}
return true;
}
}

k0r54
08-14-2004, 07:16 AM
ok its showing up fine, but the fields that are optional need to be filled in ?

Thanks Adam

I have named them like i.e OPT_mobilenumber, also is there a way i can get it where there is OPT_ and APCREG_ it is optional. so there are two types that have to be missed


thanks again adam

96turnerri
08-14-2004, 07:35 AM
not sure whats going on there then try this

function filled_out($form_vars) {
if(isset($_POST['submit'])) {
foreach ($form_vars as $key => $value)
{
if(substr($key, 0, 4) == "OPT_") {
if ($value == '') {
return false;
}
}
}
return true;
}
}

or

function filled_out($form_vars) {
if(isset($_POST['submit'])) {
foreach ($form_vars as $key => $value)
{
if(substr($key, 0, 4) == "OPT_") {
if ($value == '') {
return true;
}
} else {
if ($value == '') {
return false;
}
}
}
return true;
}
}

k0r54
08-14-2004, 07:44 AM
lol nope still dont work lol

i am filling in everything but its still not picking it up, i am now using the second one from ur last post and this code to run it


//check from data_valid to make sure all items that need to filled out are
if (!filled_out($HTTP_POST_VARS)) {
page_header();
not_filled_out();
page_footer();
}

//check that email and passwords match up
if ($email != $emailconfirm)
{
page_header();
email_error();
page_footer();
}

mysql_select_db("ebay", $conn);
mysql_query($sql, $conn) or die(mysql_error());
echo "added to the ebay database!";
}


Thanks Adam

k0r54
08-14-2004, 09:06 AM
I have corrected this to


//check from data_valid to make sure all items that need to filled out are
if (!filled_out($HTTP_POST_VARS)) {
page_header();
not_filled_out();
page_footer();
} else {

//check that email and passwords match up
if ($email != $emailconfirm)
{
page_header();
email_error();
page_footer();
} else {

mysql_select_db("ebay", $conn);
mysql_query($sql, $conn) or die(mysql_error());
echo "added to the ebay database!";
}}}


But it still dont work

Thanks Adam

k0r54
08-14-2004, 10:18 AM
I have tried all 3 types of code and style nothing.

Any idea's

Thanks Adam

96turnerri
08-14-2004, 12:27 PM
well to be honest i cant see no reason why it doesnt work, one last effort

function filled_out($form_vars) {
if(isset($_POST['submit'])) {
foreach ($form_vars as $key => $value)
{
if(strtoupper(substr($key, 0, 4)) == "OPT_") {
if ($value == "") {
return true;
}
} else {
if ($value == "") {
return false;
}
}
}
return true;
}
}