Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sticky forms 1

Status
Not open for further replies.

staffa

Programmer
Jan 31, 2005
32
DK
I have a small problem getting this (code underneath) to work. It's very simple, but i'm making myself blind trying to figure out what i'm missing.

Code:
           	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
					<table>
                    	<tr>
                        	<td>
								<font>Mandag:&nbsp;</font>
                            </td>
                            <td>
                            	<input type="text" name="hours[0]" size="2" maxlength="2" value="<?php if(isset($hours[0])) echo $hours[0]; ?>" />
								:
								<input type="text" name="minutes[0]" size="2" maxlength="2" value="<?php if(isset($minutes[0])) echo $minutes[0]; ?>" />
                            </td>
                        </tr>
                        <tr>
                        	<td>
                            	<input type="submit" name="submit" value="Ok" />
                            </td>
                        </tr>
                    </table>
				</form>

Can anyone help me??

Why destroy other people, when you already have succes in destroying yourself...
 
What exactly is not working and how should it be working? The only thing that screams out is the fact that your code seems to rely on register globals being turned on, although it is most likely they're off. Register globals should be turned off, so it is your script that would need to change.

Change the following lines to see if that solves your issue. If it does not, you will need to define your problem better.
Code:
<input type="text" name="hours[0]" size="2" maxlength="2" value="<?php if(isset($_POST['hours'][0])) echo $_POST['hours'][0]; ?>" />
:
<input type="text" name="minutes[0]" size="2" maxlength="2" value="<?php if(isset($_POST['minutes'][0])) echo $_POST['minutes'][0]; ?>" />

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
I have already tried that. Then i saw a post on another forum saing that the way i have written my code is the correct way to do it, so now i'm lost...

Why destroy other people, when you already have succes in destroying yourself...
 
I postet too soon. Thanks Vragabond, that was exactly that i needed.

Why destroy other people, when you already have succes in destroying yourself...
 
Code:
         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                    <table>
                        <tr>
                            <td>
                                <font>Mandag:&nbsp;</font>
                            </td>
                            <td>
                                <input type="text" name="hours[0]" size="2" maxlength="2" value="<?php if(isset($_POST[hours][0])) echo $_POST[hours][0]; ?>" />
                                :
                                <input type="text" name="minutes[0]" size="2" maxlength="2" value="<?php if(isset($_POST[minutes][0])) echo $_POST[minutes][0]; ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="submit" name="submit" value="Ok" />
                            </td>
                        </tr>
                    </table>
                </form>
 
oops. sorry. i should have refreshed before posting.
 
An even more slick way:

Code:
<input type="text" name="hours[0]" size="2" maxlength="2" value="<?=$_POST['hours'][0]?>" />
Men du, hvorfor bruke <font> ?

Also you could, since you want numerical input only, use dropdown lists:

Code:
<select name="hours[0]">
<?php
if (isset($hours['0'])) {
echo "<option value=\"{$hours['0']}\" selected=\"selected\">{$hours['0']}</option>";
}
?>
<option value="1">1</option>
<option value="2">2</option>
</select>

Ps. I havent tried the code, except in my head.
So take it as psuedocode.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top