Form question

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

User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Everah

Post by akimm »

i probablymanaged to mess something up, but it says i've supplied an improper argument for the foreach, isthere anything thatcould of caused this?

Code: Select all

<?php
$smiles = array('2guns', '<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>');

/**
 * This generates a drop down with
 * the array index as the key and
 * the smilie name as the value in the form
 **/
echo '<select name="smile">';
foreach ($smile as $key => $value)
{
    echo '<option value="' . $key . '">' . $value . '</option>';
}
echo '<select>';

/**
 * This makes a list of all images displayed
 **/

foreach ($smile as $key => $value)
{
    echo '<img src="/journal06/smile/' . $value . '.gif" /><br /><br />';
}
?>
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

$smiles != $smile;
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Ah...

Post by akimm »

Thank you very much, that makes a lot of sense, I missed that a few times over.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Daedalus- wrote:$smiles != $smile;
Translating from geek to English, this means that the var name $smiles is not the same as the var name $smile.

EDIT | Ok, sorry for the bad code :oops: . I didn't see it until I went back and looked at it that I did that to you. I apologize for that. The argument supplied to the foreach construct should be the var name of the array that you want to loop. Sorry for the mistake.
griffinmt
Forum Commoner
Posts: 35
Joined: Sun Jul 16, 2006 8:37 pm
Location: Michigan

Post by griffinmt »

Several posts up, it was mentioned that the content of the option value attribute can't be a tag.

In fact, it can be anything located between the quotes, including a tagged structure. BUT, it is treated as just text and passed with the post or get data as such.

In order to make that work, you will have to correctly 'balance' your use of double and single quotes.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

problems still

Post by akimm »

The code is processed, but still the images are not working.

Code: Select all

<?php
$smile = array('2guns', 'somethingElse');

/**
 * This generates a drop down with
 * the array index as the key and
 * the smilie name as the value in the form
 **/
echo '<select name="smile">';
foreach ($smile as $key => $value)
{
    echo '<option value="' . $key . '">' . $value . '</option>';
}
echo '<select>';

/**
 * This makes a list of all images displayed
 **/

foreach ($smile as $key => $value)
{
    echo '<img src="/journal06/smile/' . $value . '.gif" /><br /><br />';
}
?>
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

yea

Post by akimm »

I knew != was inequality.
it still doesn't work

It won't print the smiles, i just used two to see if perhaps two would work before i typed all 92 names. Is there an error i made or an error in the code?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Your closing select tag is missing a forward slash.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Ok

Post by akimm »

I fixed the mistake, but the code doesn't work as suggested, I keep trying to tweak little things, but nothing so far has made the images appear in the select menu, i will continue tweaking crap, if you have any idea why this might be i'm open to all suggestions.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

After you load the page and it doesn't do what you want, do a view source to see the output HTML. Post the HTML that is generated from that code so we can that.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

html output

Post by akimm »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[syntax="html"]
<form action="journalbox.php" method="POST">
<p><b>Date</b>
<input type="text" value="August 20, 2006, 8:42 pm" name="date" size="30"></p>

<p><b>Mood</b>
<select name="mood">
<option value="apathetic">apathetic
<option value="overjoyed">overjoyed
<option value="inquisitive">inquisitive
<option value="outlandish">outlandish
<option value="appreciative">appreciative
<option value="confused">confused
<option value="displeased">displeased
<option value="disgruntled">disgruntled
<option value="sick">sick
<option value="terrified">terrified
<option value="mental">mental
<option value="eruditic">eruditic
<option value="forlorn">forlorn
<option value="convuluted">convuluted
<option value="ingenious">ingenious
<option value="arrogant">arrogant
<option value="free">free
<option value="stupid">stupid
<option value="moronic">moronic
<option value="pointless">pointless
</select>

<select name="smiles">
<select name="smile"><option value="0">2guns</option><img src="/journal06/smile/2guns.gif" /><br /><br /><option value="1">somethingElse</option><img src="/journal06/smile/somethingElse.gif" /><br /><br /></select>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The HTML is wonky. Take the part about displaying the image out. That was for reference.

Logically, what you want, is a list that allows the users to see what images they want to insert. Then the user selects that image and it gets inserted. If you are trying to do this the way these forums do it, then we are in the wrong track. If you want to do where a text value is chosen from a list and then, after the form is submitted, the image shows, then on the form, run the following code:

Code: Select all

<?php
$smile = array('2guns', 'somethingElse');

/**
 * This generates a drop down with
 * the array index as the key and
 * the smilie name as the value in the form
 **/
echo '<select name="smile">';
foreach ($smile as $key => $value)
{
    echo '<option value="' . $key . '">' . $value . '</option>';
}
echo '<select>';
?>
And after it is posted, use the passed value to show the image:

Code: Select all

<?php
$img_id = $_POST['smile'];
echo '<img src="/path/to/images/' . $smile[$img_id] . '.jpg" />';
?>
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

ok

Post by akimm »

Thank you for clarifying that. I appreciate the help you've provided, I am going to test this code.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Well

Post by akimm »

Everah, it still doesn't work. I don't understand why, your code seems to haveeverything as it should be. aside from the few constants i had to change it should be working. My goal is for me since this is a journal for me only to select a word like '2guns' and it will pass this value on when it goes into the textfile, then when reprinted as html it will know it wants 2guns.gif in this space.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post what you have. Let's have a look at it.
Post Reply