PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mattcooper
Forum Contributor
Posts: 210 Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK
Post
by mattcooper » Mon Mar 27, 2006 9:41 am
Hi all,
I'm trying to make a dynamically generated form sticky - successful in every way, except for the textfields generated with the following code:
Code: Select all
$el_num = $_POST['el_menu'];
$i = 1;
$x = 5;
while($i <= $el_num){
echo "External link # $i<br><input type=\"text\" name=\"el_name_$i\" value=\""; if(isset($_POST['el_name_{$i}'])){ echo $_POST['el_name_{$i}'];}else{ echo "Label"; } echo "\" onFocus=\"MM_setTextOfTextfield('el_name_{$i}','','')\"> Example: Sponsor $i <input type\"text\" name=\"el_url_$i\" value=\""; if(isset($_POST['el_url_{$i}'])){ echo $_POST['el_url_{$i}'];}else{ echo "URL"; } echo "\" onFocus=\"MM_setTextOfTextfield('el_url_{$i}','','')\"><a href=\"help.php?context=el_urls\" target=\"_blank\"><img src=\"images/help.gif\" border=\"0\"></a><br>";
$i++;
}
}
}
The test always returns false and displays the defualt text for the textfields instead of the posted value. If I echo out "el_name_2" elsewhere i the page, it's fine. But when I try to do it using the "$i" variable, it doesn't work - even though "$i" is storing the numbers correctly.
Can anyone see what I've done wrong?
Thanks in advance!
Last edited by
mattcooper on Mon Mar 27, 2006 12:08 pm, edited 1 time in total.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Mon Mar 27, 2006 10:13 am
Variables can only be parsed inside double quotes...
mattcooper
Forum Contributor
Posts: 210 Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK
Post
by mattcooper » Mon Mar 27, 2006 10:23 am
That's what I thought, but how is it then that the other aspects of this script work fine? Everything is spot-on apart from the bit in question...
What's the fix for this? Sorry, but I just can't figure it out!!
Thanks
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Mon Mar 27, 2006 10:49 am
It's working fine in the first string because you are parsing variables in " double quotes.
The post vars:
Are being parsed in single quotes...
mattcooper
Forum Contributor
Posts: 210 Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK
Post
by mattcooper » Mon Mar 27, 2006 11:36 am
I see that... but can't figure out the fix!!
Thanks for your time...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 27, 2006 12:16 pm
mattcooper
Forum Contributor
Posts: 210 Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK
Post
by mattcooper » Mon Mar 27, 2006 1:13 pm
Thank you, Feyd. I use single quotes habitually in array parantheses, it didn't occur to me to do that! And it's only Monday...
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Mon Mar 27, 2006 1:22 pm
mattcooper wrote: Thank you, Feyd. I use single quotes habitually in array parantheses, it didn't occur to me to do that! And it's only Monday...
hawleyjr wrote: Variables can only be parsed inside double quotes...
hawleyjr wrote: It's working fine in the first string because you are parsing variables in " double quotes.
The post vars:
Are being parsed in single quotes...
mattcooper
Forum Contributor
Posts: 210 Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK
Post
by mattcooper » Tue Mar 28, 2006 5:15 am
hawleyjr wrote: It's working fine in the first string because you are parsing variables in " double quotes.
The post vars:
Are being parsed in single quotes...
Far too cryptic for me when my head is fried at the end of a working day... sorry fella.