Page 1 of 1

How to grab the whole value of a text box?

Posted: Fri Jun 13, 2003 11:15 am
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,

Posted: Fri Jun 13, 2003 11:46 am
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

Posted: Fri Jun 13, 2003 11:56 am
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?

Posted: Fri Jun 13, 2003 12:39 pm
by twigletmac
You could just do a str_replace():

Code: Select all

$filename = str_replace(' ', '_', $filename);
Mac

Posted: Fri Jun 13, 2003 12:43 pm
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.

Posted: Sat Jun 14, 2003 3:02 am
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

Posted: Mon Jun 16, 2003 9:58 am
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.

Posted: Mon Jun 16, 2003 10:17 am
by twigletmac
Could we see the full code (including HTML) for the combo box?

Mac

Posted: Mon Jun 16, 2003 10:22 am
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.


Posted: Mon Jun 16, 2003 10:30 am
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

Posted: Mon Jun 16, 2003 10:35 am
by slipstream
Works perfect, thank a lot :D