Sponsored Content
Top Forums Web Development Php help to copy form field if empty Post 302918314 by Akshay Hegde on Monday 22nd of September 2014 11:01:50 PM
Old 09-23-2014
Don't use empty unless you are sure that's what you want:

Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE.

The following things are considered to be empty:

Code:
       "" (an empty string)
       0 (0 as an integer)
       0.0 (0 as a float)
       "0" (0 as a string)
       NULL
       FALSE
       array() (an empty array)
       $var; (a variable declared, but without a value)

Usually the array_key_exists check should suffice.

Code:
<?php

$arr = array('a' => 0); $key = 'a';
var_dump(array_key_exists($key, $arr)); // -->  TRUE
var_dump(empty($arr[$key])); // -->  TRUE

if(array_key_exists($key, $arr)) {
    echo "key $key exists\n";
}

if(empty($arr[$key])) {
    echo "empty\n";
}
?>

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Count of Field for Non-Empty

Hi Guys, I wanted to count the number of records for a particular field of a file. whose fields are separated by comma"," I fI use this command. cat "filename" cut -sd "," -f13 | wc -l This shows all the lines count including the blank values for the field number 13. I wanted to count... (2 Replies)
Discussion started by: Swapna173
2 Replies

2. Filesystems, Disks and Memory

DD copy excluding empty blocks?

I'm not 100% sure if this was the right place to post in but here i go: I'm attempting to migrate a physical windows disk onto my SAN through the use of the dd copy command. I'm booting into knoppix, running dd, and then bringing the server back up into windows running on the SAN. Everything... (2 Replies)
Discussion started by: Merkilo
2 Replies

3. Shell Programming and Scripting

Format the file by deleting empty field

I have the test data with 10 column separated by comma and each column has more than 1000000 rows. Can anyone help me to find empty field in all columns and delete that empty field alone and lift that column up by one row. Data with empty field: A74203XYZ,A21718XYZ,A72011XYZ,A41095XYZ,... (7 Replies)
Discussion started by: zooby
7 Replies

4. Shell Programming and Scripting

Converting form field to table format

May data Name = Andi Address = none Phone = 82728 Name = Peter Address = none Phone = 98799 The expected output Name,Address,Phone Andi,none,82728 Peter,none,98799 what i have done (6 Replies)
Discussion started by: before4
6 Replies

5. UNIX for Dummies Questions & Answers

remove empty field

Hi all ! I'm sure it is a basic question but I didn't find any threads that fit my need. How to remove empty fields with awk? Or in other words, how to shift all the fields after an empty field on the left? input: 1|2||3|4|5||6 wanted: 1|2|3|4|5|6 I tried: awk '{for(i=1; i<=NF;... (7 Replies)
Discussion started by: lucasvs
7 Replies

6. Shell Programming and Scripting

print non empty column/field value

I have below file 25-09-2012 24-09-2012 19-09-2012 31-07-2012 30-04-2012 30-03-2012 ASIAEXFVNV N/A CEU 4 DMIRSOA N/A CAS 2 2 2 DMIRSOA N/A MIDMT 2 NFIAL22 N/A HVNY 11 11 11 NFIAL22 N/A NYAL3 11 11 11 NFIAL22 N/A NYCN 11 11 11 ... (4 Replies)
Discussion started by: manas_ranjan
4 Replies

7. Shell Programming and Scripting

Copy last third char form string

HI Input A.txt ABC907 ABC907_1B_9 ABC985 ABC985_1A_9 ABC985 ABC985_1B_9 ABC985 ABC985_1C_9 ABC05037 ABC05037_1A_9 ABC05037 ABC05037_1B_9 Base of column 2 last third char. If It is A the 1,if B then 2 If C then 3 File B.txt ABC907 ABC907_1B_9 2 ABC985 ABC985_1A_9 1 ABC985... (8 Replies)
Discussion started by: asavaliya
8 Replies

8. Shell Programming and Scripting

How to detect empty field in awk ?

Hi ! programmers I have a need of detecting empty field in file my file looks like this 40.900|-71.600|1.6|20|1|1961|21.00|3.700||1|US|28035|10029370|31 40.900|-71.600|5.7|20|1|1961|21.00|3.700||1|US|28035|10029370|31 40.900|-71.600|7.8|20|1|1961|21.00|3.700||1|US|28035|10029370|31... (7 Replies)
Discussion started by: Dona Clara
7 Replies

9. Shell Programming and Scripting

Cgi to dump xml data from form input field

Hi All, I am trying to write a shell script which takes parse the web form find the input field and dump the data of that field into one xml file. The form looks like, <input type="button" id="btnSave" value="Save" onclick="saveXmlData()"/> <form name="submitForm"... (1 Reply)
Discussion started by: jdp
1 Replies

10. UNIX for Dummies Questions & Answers

Copy non-empty files into subdirectory

How to Copy non-empty files into subdirectory I have directory A there are bunch of files: a.txt a.txt.target b.txt b.target.txt....... How can i find out the non-empty file within *.txt.target and copy them into a subdirectory B? Thank you. (2 Replies)
Discussion started by: grace_shen
2 Replies
HTML::FormHandler::Field::Repeatable(3pm)		User Contributed Perl Documentation		 HTML::FormHandler::Field::Repeatable(3pm)

NAME
HTML::FormHandler::Field::Repeatable - repeatable (array) field VERSION
version 0.40013 SYNOPSIS
In a form, for an array of hashrefs, equivalent to a 'has_many' database relationship. has_field 'addresses' => ( type => 'Repeatable' ); has_field 'addresses.address_id' => ( type => 'PrimaryKey' ); has_field 'addresses.street'; has_field 'addresses.city'; has_field 'addresses.state'; In a form, for an array of single fields (not directly equivalent to a database relationship) use the 'contains' pseudo field name: has_field 'tags' => ( type => 'Repeatable' ); has_field 'tags.contains' => ( type => 'Text', apply => [ { check => ['perl', 'programming', 'linux', 'internet'], message => 'Not a valid tag' } ] ); or use 'contains' with single fields which are compound fields: has_field 'addresses' => ( type => 'Repeatable' ); has_field 'addresses.contains' => ( type => '+MyAddress' ); If the MyAddress field contains fields 'address_id', 'street', 'city', and 'state', then this syntax is functionally equivalent to the first method where the fields are declared with dots ('addresses.city'); You can pass attributes to the 'contains' field by supplying a 'contains' hashref. has_field 'addresses' => ( type => 'Repeatable, init_contains => { wrapper_attr => { class => ['hfh', 'repinst'] } }, ); DESCRIPTION
This class represents an array. It can either be an array of hashrefs (compound fields) or an array of single fields. The 'contains' keyword is used for elements that do not have names because they are not hash elements. This field node will build arrays of fields from the the parameters or an initial object, or empty fields for an empty form. The name of the element fields will be an array index, starting with 0. Therefore the first array element can be accessed with: $form->field('tags')->field('0') $form->field('addresses')->field('0)->field('city') or using the shortcut form: $form->field('tags.0') $form->field('addresses.0.city') The array of elements will be in "$form->field('addresses')->fields". The subfields of the elements will be in a fields array in each element. foreach my $element ( $form->field('addresses')->fields ) { foreach my $field ( $element->fields ) { # do something } } Every field that has a 'fields' array will also have an 'error_fields' array containing references to the fields that contain errors. Complications When new elements are created by a Repeatable field in a database form an attempt is made to re-load the Repeatable field from the database, because otherwise the repeatable elements will not have primary keys. Although this works, if you have included other fields in your repeatable elements that do *not* come from the database, the defaults/values must be able to be loaded in a way that works when the form is initialized from the database item. This is only an issue if you re-present the form after the database update succeeds. ATTRIBUTES
index This attribute contains the next index number available to create an additional array element. num_when_empty This attribute (default 1) indicates how many empty fields to present in an empty form which hasn't been filled from parameters or database rows. num_extra When the field results are built from an existing object (item or init_object) an additional number of repeatable elements will be created equal to this number. Default is 0. add_extra When a form is submitted and the field results are built from the input parameters, it's not clear when or if an additional repeatable element might be wanted. The method 'add_extra' will add an empty repeatable element. $form->process( params => {....} ); $form->field('my_repeatable')->add_extra(1); This might be useful if the form is being re-presented to the user. AUTHOR
FormHandler Contributors - see HTML::FormHandler COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Gerda Shank. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-25 HTML::FormHandler::Field::Repeatable(3pm)
All times are GMT -4. The time now is 10:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy