473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

sticky form with dynamically generated form element?

Hello,

could someone show me how to make sticky form with dynamically
generated form element? for example, if one likes to make the
dynamically generated check box (and its name) 'sticky' that retains
the value of the previously submitted value. How would one do that?
TIA.

I was thinking something along this line but not sure it's the right
way to accomplish this task

<?php
echo "<input name='$dynamicallygenerated' value='$temp'
type='checkbox' />";
$temp= $_POST[$dynamicallygenerated];
?>
Oct 24 '08 #1
9 2757
On Fri, 24 Oct 2008 22:37:01 +0200, <st***********@gmail.comwrote:
Hello,

could someone show me how to make sticky form with dynamically
generated form element? for example, if one likes to make the
dynamically generated check box (and its name) 'sticky' that retains
the value of the previously submitted value. How would one do that?
TIA.

I was thinking something along this line but not sure it's the right
way to accomplish this task

<?php
echo "<input name='$dynamicallygenerated' value='$temp'
type='checkbox' />";
$temp= $_POST[$dynamicallygenerated];
?>

Something like:
printf("<input name='%s' value='%s' type='text'>",
$name,
isset($_POST[$name]) ? htmlspecialchars($_POST[$name], ENT_QUOTES) :
'default');

Checkboxes are usually more like:
printf("<input name='%s' value='%s' type='checkbox' %s>",
$name,
$value,
isset($_POST[$name]) ? 'selected' : '');

Allthough depending on the exact use of these 'sticky' values one could be
better of just storing the values in a session.
--
Rik
Oct 24 '08 #2
Rik Wasmus wrote:
[snip]
Checkboxes are usually more like:
printf("<input name='%s' value='%s' type='checkbox' %s>",
$name,
$value,
isset($_POST[$name]) ? 'selected' : '');
A bit OT, but this affects the desired result requested by the OP:
"selected" does not work on checkboxes. This last line of quoted code
should read something like:

isset($_POST[$name]) ? 'checked="checked"' : '');

Although simply using "checked" can suffice, it is better to use the
long form. This way, it should always be valid, such as when applied
in XHTML documents.

</pedantic>
>
Allthough depending on the exact use of these 'sticky' values one could
be better of just storing the values in a session.
--
Curtis
Oct 25 '08 #3
On Sat, 25 Oct 2008 11:35:13 +0200, Curtis <dy****@gmail.comwrote:
Rik Wasmus wrote:
[snip]
>Checkboxes are usually more like:
printf("<input name='%s' value='%s' type='checkbox' %s>",
$name,
$value,
isset($_POST[$name]) ? 'selected' : '');

A bit OT, but this affects the desired result requested by the OP:
"selected" does not work on checkboxes. This last line of quoted code
should read something like:

isset($_POST[$name]) ? 'checked="checked"' : '');

Although simply using "checked" can suffice, it is better to use the
long form. This way, it should always be valid, such as when applied in
XHTML documents.
Hehe, you're right, however, as his example input fields did not self
close I assumed HTML, and I'd use just 'checked' instead of the long form
here.
--
Rik
Oct 25 '08 #4
Thank you both very much for your help. Would that still work if
'$name' String is manipulated prior to submission? I played with a
simple example just to find out but got into trouble already... could
you show me where I got it wrong? Thanks again.

<html>

<?php

echo $_POST['test']; // this line worked fine

// manipulation 2 lines below
$temp1="te"."st";
$temp2="'te"."st'"; // add single quote

echo $_POST[$temp1]; // this line not working, prints blank
echo $_POST[$temp2]; // this line not working, prints blank

?>

<body>
<form action="self.php" method="post">
<select name="test">
<option>Select</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<input name="Submit" type="submit" value="submit">
</form>
</body>
</html>
Nov 3 '08 #5
st***********@gmail.com wrote:
Thank you both very much for your help. Would that still work if
'$name' String is manipulated prior to submission? I played with a
simple example just to find out but got into trouble already... could
you show me where I got it wrong? Thanks again.

<html>

<?php

echo $_POST['test']; // this line worked fine

// manipulation 2 lines below
$temp1="te"."st";
$temp2="'te"."st'"; // add single quote

echo $_POST[$temp1]; // this line not working, prints blank
This line should just work... Are these the exact lines you're testing?
Please do a var_dump($temp1), and look at the source of the output, not
how it's rendered in a browser...
echo $_POST[$temp2]; // this line not working, prints blank
This shouldn't work indeed, as there isn't a string in the posted
key/name (otherwise, you'd have to do a echo $_POST["'test'"]; for it to
work.
--
Rik
Nov 3 '08 #6
Rik,

Thanks for responding.

I tried what you suggested using var dump and got the followings:

temp1 =string(4) "test", temp2 =string(6) "'test'"

but still no print out from 'echo $_POST[$temp1];' neither on
Firefox(3.0.3) nor IE7. I was searching on the internet and has yet to
find an example of $_POST[] with a variable $whatever inside.
Nov 4 '08 #7
st***********@gmail.com wrote:
Rik,

Thanks for responding.

I tried what you suggested using var dump and got the followings:

temp1 =string(4) "test", temp2 =string(6) "'test'"

but still no print out from 'echo $_POST[$temp1];' neither on
Firefox(3.0.3) nor IE7. I was searching on the internet and has yet to
find an example of $_POST[] with a variable $whatever inside.
There is nothing special about using a variable inside of $_POST[].
$_POST is just an array.

What do you get if you replace your PHP code with the following?

$temp1 = "te"."st";
echo '<pre>';
print_r($_POST);
echo $temp1 . "\n";
echo $_POST[$temp1] . "\n";
echo '</pre>';

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 4 '08 #8
On Nov 4, 6:58*am, Jerry Stuckle <jstuck...@attglobal.netwrote:
student4li...@gmail.com wrote:
Rik,
Thanks for responding.
I tried what you suggested using var dump and got the followings:
temp1 =string(4) "test", *temp2 =string(6) "'test'"
but still no print out from 'echo $_POST[$temp1];' neither on
Firefox(3.0.3) nor IE7. I was searching on the internet and has yet to
find an example of $_POST[] with a variable $whatever inside.

There is nothing special about using a variable inside of $_POST[].
$_POST is just an array.

What do you get if you replace your PHP code with the following?

$temp1 = "te"."st";
echo '<pre>';
print_r($_POST);
echo $temp1 . "\n";
echo $_POST[$temp1] . "\n";
echo '</pre>';

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Jerry,

I see the followings on both Firefox and IE:
Array
(
)
test
Nov 4 '08 #9
st***********@gmail.com wrote:
On Nov 4, 6:58 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>student4li...@gmail.com wrote:
>>Rik,
Thanks for responding.
I tried what you suggested using var dump and got the followings:
temp1 =string(4) "test", temp2 =string(6) "'test'"
but still no print out from 'echo $_POST[$temp1];' neither on
Firefox(3.0.3) nor IE7. I was searching on the internet and has yet to
find an example of $_POST[] with a variable $whatever inside.
There is nothing special about using a variable inside of $_POST[].
$_POST is just an array.

What do you get if you replace your PHP code with the following?

$temp1 = "te"."st";
echo '<pre>';
print_r($_POST);
echo $temp1 . "\n";
echo $_POST[$temp1] . "\n";
echo '</pre>';

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Jerry,

I see the followings on both Firefox and IE:
Array
(
)
test
Then your $_POST variable is empty. You are submitting the form before
checking, aren't you? Remember - PHP code runs on the server, and the
page will complete before anything is displayed in the client.
Resubmitting the form will run the PHP code again, this time with
something in the $_POST array (assuming, of course, you posted something).

You ARE posting a form back, aren't you? (You didn't show that html).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 4 '08 #10

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

Similar topics

7
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...
0
by: Adam Retter | last post by:
Hi Guys, I have a need to create a html form based on my schema. I initially decided to do this using xql, have got some way but am finding this difficult (it may be as I am very new to xql)....
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
7
by: Tom wilson | last post by:
I'm trying to create dynamic controls in ASP.Net. It's driving me nuts. I keep getting the error: Control '16' of type 'RadioButton' must be placed inside a form tag with runat=server. Dim...
1
by: Ajar | last post by:
Is there any way to retrieve the type(checkbox,radio...) of the form field from cgi.FieldStorage. I tried something like form.type, but this field seems to be None for all the form fields
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
3
by: Ralph | last post by:
Hi I have small function to generate my form controls: function buildInput(sType, vValue, vId, sName, sLabel){ var oInput = null; var oLabel = document.createElement('label'); var oCont =...
5
by: phpCodeHead | last post by:
I am needing to determine how to go about validating that a field in my form contains only a positive integer. I know that this is fairly simple if the form contains only one element to be...
3
by: MitchellEr | last post by:
Hi, I am in the process of creating several forms where a group of elements on the form need to be created dynamically. For example, in the case of one of the forms, I have a drop down for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...

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.