Re: im so stupid

From: Date: Tue, 12 Feb 2002 15:39:32 +0000
Subject: Re: im so stupid
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-12028@lists.php.net to get a copy of this message
So, do not rely on BUTTONS as variables in scripts since browsers are FUNKY and button variables don't always get set as they should. Use hidden variables. If you have different buttons doing different things, such as (delete, submit, open, etc.), then make each button call a javascript to set the value of the hidden variable like so: <form name="myForm" method="post" action="phpscript.php"> <input type="button" name="edit" onClick="javascript: this.form.action.value='edit';"> <input type="button" name="delete" onClick="javascript: this.form.action.value='delete';"> <input type="submit" name="Submit" onClick="javascript: this.form.action.value='submit';"> <input type="hidden" name="action"> <!-- this value will be set by the button that gets clicked by user --> </form> THis always works for me! Nicole Amashta www.aeontrek.com ============================== "Nicole Amashta" <430ntr3k@bellsouth.net> wrote in message news:20020212153408.58762.qmail@pb1.pair.com... > AHA! That is it, and I've encountere this before. > > OK, actually $submit should be set. But do this instead: > > add a hidden tag to the form as such: > > ================= > <form method="post" action="registrer.php"> > > Fornavn: <input type="text" name="fornavn"><br> > > Etternavn: <input type="text" name="etternavn"><br> > > <input type="Submit" name="submit" value="Registrer"> > > <input type="hidden" name="action" value="submit"> > > </form> > > ================= > > Then, in your php script, do this: > > if ( $action == "submit" ) > { > ## do the action here .... > } > ================ > > > This is how I handle my forms. I use hidden tags with values that will most > certainly be passed to the script. If the submit button is not clicked, that > value doesn't get set, thus not showing up to the calling script. But, if > you actually click the button, it will. If you are just hitting your "enter" > or "spacebar" to submit the form, then the $submit is never set. > > -Nicole Amashta > www.aeontrek.com > > ============================= > > "Court Shrock" <ShrockC@inhs.org> wrote in message > > news:25E1EA6CA52DD311A525009027725B5504142471@exchange1.inhs.org... > > > registrer.html -> > > > > > > <html> > > > <head></head> > > > <body><form method="post" action="registrer.php"> > > > Fornavn: <input type="text" name="fornavn"><br> > > > Etternavn: <input type="text" name="etternavn"><br> > > > <input type="Submit" name="submit" > > > value="Registrer"><br> </form> > > > > I do not think that an input of type 'submit' will be submitted in the > post > > to the next page...you could verify this by doing a phpinfo at the top of > > registrer.php....the only name/value pairs submitted in the above form > > should be "fornavn" and "etternavn". > > > > > </body> > > > </html> > > > > > > registrer.php -> > > > > > > <? > > > IF (isset($submit)) > > > > ...and therefore, the above statement would fail because the $submit > > variable is not set and therefore the intended code below would not be > > executed.... > > > > > { > > > $hostname = "dbname"; > > > $username = "chris"; > > > $password = "*****"; > > > $dbname = "chris"; > > > MSSQL_CONNECT($hostname,$username,$password); > > > mssql_select_db($dbname); > > > $sql = "insert into studenter(fornavn, etternavn) values > > > ('$fornavn','$etternavn')"; > > > $result = mssql_query($sql); > > > $studentnummer = mssql_insert_id(); > > > Print("Studenten er lagt inn!"); > > > } > > > ?> > >

« previous php.windows (#12028) next »