473,562 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Capturing HTML form field names even when they are blank

JDS
Hi, all. I'd like to do the following, preferably *without* resorting to
javascript:

I have a long, dynamically-generated form questionnaire. Not all of the
form fields are dynamically generated, though.

I'd like to capture the NAME of every HTML form field element on the
server, even if that element is submitted blank. The trouble is, with,
say, radio buttons or checkboxes for example, a *blank* element does not
get submitted at all.

Example:
<form action="text.ph p">
<input type="radio" name="firstbutt on" value="1">
<input type="radio" name="firstbutt on" value="2">
<input type="radio" name="firstbutt on" value="2">
<input type="text" name="thetextbo x">
</form>

text.php
<?php
print_r($_REQUE ST);
?>

If the form is submitted completely blank, text.php prints out:

Array
(
[thetextbox] =>
)

ONLY if I click a value on one of the radio buttons do I get the field
"firstbutto n", e.g.:

Array
(
[thetextbox] =>
[firstbutton] => 1
)

How can I get the names of all of the fields in the HTML form even if they
are sent blank? I am considering using JavaScript onSubmit() to put fake
values in for blank fields, but using JS is not desirable. I had been
putting hidden fields in with the field name "field_name s[nameoffield]"
for each form field but this does not scale well for any non-dynamic form
fields.

Any other ideas?

--
JDS | je*****@go.away .com
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #1
7 3212
DH
JDS wrote:
Hi, all. I'd like to do the following, preferably *without* resorting to
javascript:

I have a long, dynamically-generated form questionnaire. Not all of the
form fields are dynamically generated, though.

I'd like to capture the NAME of every HTML form field element on the
server, even if that element is submitted blank. The trouble is, with,
say, radio buttons or checkboxes for example, a *blank* element does not
get submitted at all.

Example:
<form action="text.ph p">
<input type="radio" name="firstbutt on" value="1">
<input type="radio" name="firstbutt on" value="2">
<input type="radio" name="firstbutt on" value="2">
<input type="text" name="thetextbo x">
</form>

text.php
<?php
print_r($_REQUE ST);
?>

If the form is submitted completely blank, text.php prints out:

Array
(
[thetextbox] =>
)

ONLY if I click a value on one of the radio buttons do I get the field
"firstbutto n", e.g.:

Array
(
[thetextbox] =>
[firstbutton] => 1
)

How can I get the names of all of the fields in the HTML form even if they
are sent blank? I am considering using JavaScript onSubmit() to put fake
values in for blank fields, but using JS is not desirable. I had been
putting hidden fields in with the field name "field_name s[nameoffield]"
for each form field but this does not scale well for any non-dynamic form
fields.

Any other ideas?


Perhaps this will help, or give you some ideas:

$buffer = '';

while(list($key , $val) = each($_POST)){
if(!is_array($v al)){
$val = stripslashes(tr im($val));
$buffer .= $key.': '.$val."\n";
}else{
foreach(array_k eys($val) as $key){
$val[$key] = stripslashes(tr im($val));
$buffer .= $val[$key].': '.$val."\n";
}
}
}

echo "\n".nl2br($buf fer);
Jul 17 '05 #2

JDS wrote:

[snip]
Example:
<form action="text.ph p">
<input type="radio" name="firstbutt on" value="1">
<input type="radio" name="firstbutt on" value="2">
<input type="radio" name="firstbutt on" value="2">
<input type="text" name="thetextbo x">
</form>


To do what you want, you have to initialize the fields using
"type=hidde n". For example, using your example code:
<form action="text.ph p" method="POST">
<input type="hidden" name="firstbutt on" value="0">
<input type="radio" name="firstbutt on" value="1">
<input type="radio" name="firstbutt on" value="2">
<input type="radio" name="firstbutt on" value="3">
<input type="text" name="thetextbo x">
</form>

Now when someone submits the form without selecting anything, you will
get a value of "0" in the variable $_POST['firstbutton'].

You should be able to extend this technique to your real form.

Ken

Jul 17 '05 #3
JDS wrote:
I'd like to capture the NAME of every HTML form field element on the
server, even if that element is submitted blank. The trouble is, with,
say, radio buttons or checkboxes for example, a *blank* element does not
get submitted at all.
Well sorry, you can't.
Example:
<form action="text.ph p">
<input type="radio" name="firstbutt on" value="1">
<input type="radio" name="firstbutt on" value="2">
<input type="radio" name="firstbutt on" value="2">
<input type="text" name="thetextbo x">
</form>


<form action="text.ph p">
<input type="radio" name="firstbutt on" value="1">
<input type="radio" name="firstbutt on" value="2">
<input type="radio" name="firstbutt on" value="2">
<input type="text" name="thetextbo x">
<input type="hidden" name="FIELDS" value="thetextb ox,firstbutton" >
</form>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jul 17 '05 #4
On Mon, 07 Feb 2005 14:50:51 -0500, JDS <je*****@go.awa y.com> wrote:
Hi, all. I'd like to do the following, preferably *without* resorting to
javascript:

I have a long, dynamically-generated form questionnaire. Not all of the
form fields are dynamically generated, though.

I'd like to capture the NAME of every HTML form field element on the
server, even if that element is submitted blank. The trouble is, with,
say, radio buttons or checkboxes for example, a *blank* element does not
get submitted at all.
This behaviour is required by the HTML standard:

http://www.w3.org/TR/html401/interac...html#h-17.13.2
http://www.w3.org/TR/html401/interact/forms.html#radio
Example:
<form action="text.ph p">
<input type="radio" name="firstbutt on" value="1">
<input type="radio" name="firstbutt on" value="2">
<input type="radio" name="firstbutt on" value="2">
<input type="text" name="thetextbo x">
</form>

If the form is submitted completely blank, text.php prints out:

Array
(
[thetextbox] =>
)

ONLY if I click a value on one of the radio buttons do I get the field
"firstbutton ", e.g.:

Array
(
[thetextbox] =>
[firstbutton] => 1
)

How can I get the names of all of the fields in the HTML form even if they
are sent blank? I am considering using JavaScript onSubmit() to put fake
values in for blank fields, but using JS is not desirable. I had been
putting hidden fields in with the field name "field_name s[nameoffield]"
for each form field but this does not scale well for any non-dynamic form
fields.


Adding extra elements is AFAIK the only method, given that HTML requires that
non-selected radio buttons are not successful.

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
JDS
On Mon, 07 Feb 2005 20:50:37 +0000, Toby Inkster wrote:
Well sorry, you can't.


Allright. Thanks all. I had been using hidden fields, anyways, which was
fine for the dynamically-generated form fields because I can just have the
hidden fields dynamically generated as well.

However, manually putting in hiddens for the other fields does not scale
well and is prone to errors. Oh well, I'll figure something out.

Yum, coffee.

--
JDS | je*****@go.away .com
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #6
JDS wrote:
On Mon, 07 Feb 2005 20:50:37 +0000, Toby Inkster wrote:

Well sorry, you can't.

Allright. Thanks all. I had been using hidden fields, anyways, which was
fine for the dynamically-generated form fields because I can just have the
hidden fields dynamically generated as well.

However, manually putting in hiddens for the other fields does not scale
well and is prone to errors. Oh well, I'll figure something out.


Read the HTML spec. For radio buttons, one option must *always*
be selected. Therefore, the case you site should not happen,
there should always be one selected and so one should always be
submitted.

<URL:http://www.w3.org/TR/html401/interact/forms.html#radi o>

radio buttons

Radio buttons are like checkboxes except that when several share
the same control name , they are mutually exclusive: when one is
switched "on", all others with the same name are switched "off".
The INPUT element is used to create a radio button control.

If no radio button in a set sharing the same control name is
initially "on", user agent behavior for choosing which control
is initially "on" is undefined. Note. Since existing
implementations handle this case differently, the current
specification differs from RFC 1866 ( [RFC1866] section
8.1.2.4), which states:

At all times, exactly one of the radio buttons in a set is
checked. If none of the <INPUT> elements of a set of radio
buttons specifies `CHECKED', then the user agent must check
the first radio button of the set initially.

Since user agent behavior differs, authors should ensure that in
each set of radio buttons that one is initially "on".

*Note the last sentence.*
--
Fred
Jul 17 '05 #7
JDS
On Wed, 09 Feb 2005 01:49:27 +1000, Fred Oz wrote:
Since user agent behavior differs, authors should ensure that in each
set of radio buttons that one is initially "on".

*Note the last sentence.*


Great! Thanks for the info! This is very enlightening.

--
JDS | je*****@go.away .com
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5081
by: dmcconkey | last post by:
Hi folks, I have a client with four websites. Each site has a contact form that is identical. They all have "required" fields validated through a JavaScript onSubmit() function. Upon validation, post values go to a PHP processing page that adds values to a database and generates an email to someone in marketing. For three of these sites,...
4
2353
by: Andrew Williams | last post by:
Does anyone know of a way to quickly validate an HTML web form? I need to make sure that certain fields on my form actually contain data and are not submitted blank. I have tried using client-side Javascript validation which flags up when a field is empty but the form is still submitted. Here is the ASP code I am using to submit the form...
7
2556
by: JDS | last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to JavaScript: I have a long, dynamically-generated form questionnaire. Not all of the form fields are dynamically generated, though. I'd like to capture the NAME of every HTML form field element on the server, even if that element is submitted blank. The trouble is,...
33
5580
by: Joerg Schuster | last post by:
Hello, Python regular expressions must not have more than 100 capturing groups. The source code responsible for this reads as follows: # XXX: <fl> get rid of this limitation! if p.pattern.groups > 100: raise AssertionError( "sorry, but this version only supports 100 named groups"
4
2859
by: kathy | last post by:
Working in a form, I have an Iif statement where if a date is not filled in, another field will show as a blank. If the date IS filled in, the 2nd field will show its actual value. The following statement is in the Control Source of the field =IIf(IsNull()," ",) So, the results I get are this: If the date field is blank, my field is...
2
1579
by: Chris Windsor | last post by:
I hope the following describe what I'm trying to do: I have created a tool to be used by product analysts when studying different cell phone designs. Part of the tool is a set of 11 forms on a tab structure with fields for various features a phone might have; there are almost 100 of these features to choose from. Rather than a simple check...
0
6422
by: lawrenceS59 | last post by:
Hi all, I'm fairly new to web development so bare with me. The html page that i've created isn't working and i can't figure out why. I'm guessing there are some rules that need to be followed when putting xml between the <textarea></textarea> tags. The textarea and the submit buttons are located inside <form> tags. When a button is pressed...
2
2809
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07, 2007 reference #: 0415 from: operating account
15
5245
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to show - text boxes, input boxes, buttons, hyperlinks ie the usual. The data is not obtained directly from a database.
0
7577
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7869
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7627
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7935
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6221
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5477
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3608
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2073
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.