How to grab the whole value of a text box?

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

Post Reply
slipstream
Forum Commoner
Posts: 86
Joined: Fri Apr 19, 2002 8:53 am
Location: Canada

How to grab the whole value of a text box?

Post by slipstream »

I have a text box like so:

echo 'Enter the new Docket number here <input type="text" size = 30 name="docketNum">';

then in another php file I create my file like this:

$file2=fopen("dockets/".$docketNum.".txt", "a+");
fwrite($file2, "");
fclose($file2);

The problem is, if I call the docket "hello everyone" it will only make a file called "hello.txt" when it should be called "hello everyone.txt". Does that make any sense?

thanks,
User avatar
skehoe
Forum Commoner
Posts: 59
Joined: Sun Dec 22, 2002 5:57 am
Location: Denver

Post by skehoe »

Hey there,

you may want to try replacing the white space in the submit with an underscore and see if that works. PHP may not want to create files with spaces in the name.

~Scott
slipstream
Forum Commoner
Posts: 86
Joined: Fri Apr 19, 2002 8:53 am
Location: Canada

Post by slipstream »

but do I have to find the spaces and replace them myself? The user will be entering the name that's why. I can't just say "use underscores instead of spaces please" See what I mean?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You could just do a str_replace():

Code: Select all

$filename = str_replace(' ', '_', $filename);
Mac
slipstream
Forum Commoner
Posts: 86
Joined: Fri Apr 19, 2002 8:53 am
Location: Canada

Post by slipstream »

Sorry guys I messed up here. I can create the file fine. It's when the user select the file name from a combo box it only takes the first word.

ex.

If my they select "hello there" from the combo box.

Then when I echo my cboDocket variable I only get "hello"

The problem is with the box, not file, sorry.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could we see the code for your combo box? You probably need to add quotes around the attribute values in the HTML.

Mac
slipstream
Forum Commoner
Posts: 86
Joined: Fri Apr 19, 2002 8:53 am
Location: Canada

Post by slipstream »

I am echoing my combo box like this:

echo $cboDock;


this is where it only takes the first word of the combo box.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could we see the full code (including HTML) for the combo box?

Mac
slipstream
Forum Commoner
Posts: 86
Joined: Fri Apr 19, 2002 8:53 am
Location: Canada

Post by slipstream »

Sure, here is the html portion.

$file = file('docket.txt'); // returns an array with each line in a new array pos
$totHours = 0;

echo ' Docket Numbers <select name="cboDock" size=1>';
foreach($file as $line)
{
$info = explode('|', $line);
echo '<option value='.$info[0].'> '.$info[0];
//echo "<td>" . $info[0] . "</td>";
}
echo '</select><BR><BR>';

that's where I fil my box and it works. Now here is the PHP where I echo it for a test:

echo $cboDock;

Like I said it will only echo the first word.

User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The problem is that you have no quotes around the value attribute's value - this means that in the source you will have something like this:

Code: Select all

&lt;option value=test value&gt;test value
and the browser cannot tell that the second value actually belongs to the value attribute. To correct this problem, change:

Code: Select all

echo '<option value='.$info[0].'> '.$info[0];
to

Code: Select all

echo '<option value="'.$info[0].'">'.$info[0].'</option>';
and then the source code for the page will have this in it:

Code: Select all

&lt;option value="test value"&gt;test value&lt;/option&gt;
which makes it explicit to the browser what belongs with what.

Mac
slipstream
Forum Commoner
Posts: 86
Joined: Fri Apr 19, 2002 8:53 am
Location: Canada

Post by slipstream »

Works perfect, thank a lot :D
Post Reply