homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

php problem
how to use array contents in form?

 7:23 am on Feb 22, 2001 (gmt 0)

I have a couple of array elements which contain 2-3 word strings. I tried to use the contents of these elements as the default value of a text input box, but only the first word appears.

for example if $my_array[0] = 15th of February, only '15th' appears when I try to use it in the way I mentioned (<input type=text name=date value=$my_array[0]>) I also tried to use array element in mailto link for subject and had same problem.



 10:18 am on Feb 22, 2001 (gmt 0)

Hi anton, welcome to Webmaster World.

The problem is in your HTML rather than the PHP. You need to enclose $my_array[0] in quotes, or the other words following '15th' will be treated as tag attributes by the browser.

print("<input type=\"text\" name=\"date\" value=\"$my_array[0]\">");
will do the trick - note that the "s are 'escaped' by using a backslash before them to avoid syntax errors.


 2:14 pm on Feb 22, 2001 (gmt 0)

Thanks, that did the trick, but I also want to use an array element in a mailto link eg mailto:$my_array[2]?subject=$my_array[3]

I tried enclosing these in escaped quotes but it still didn't work. Any idea on this one?

Thanks heaps for your help...


 8:55 pm on Feb 22, 2001 (gmt 0)

Hmm... first of all I'm assuming the content of $my_array[2] is a valid email address?

It's a good idea to get into the habit of enclosing all HTML attribute values in quotes, as it's required in XML and XTML which is where we're all heading eventually... so, your line would look something like:

<? print("<a href=\"mailto:$my_array[2]?subject=$my_array[3]\">"); ?>

Does that work for you?


 12:33 am on Feb 23, 2001 (gmt 0)

Yes, that fixed it. I've just got into the habit of not using quotes because I've been able to get away with it so often with HTML.

Thanks heaps :-)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved