jihmantiquilla Posted October 1, 2009 Share Posted October 1, 2009 gud day, i'm new in here phpfreaks and also new into php programming, javascript. but an experienced programmer with regards to .net, i'am juz confused with regards to the submission and validation of forms. when i started to submit the page. the values on the pass and pass2 textboxes always disapper.:( this is my code javascript function checkTextboxes() { f=document.form1; f.command.value="Add"; f.submit; } html <input name="btnSubmit" type="submit" value="Submit" onclick="checkTextboxes()" style="position:absolute;left:211px;top:527px;z-index:27"> php <? if($_REQUEST['command']=='Add') { $pass=$_REQUEST['txtPass']; $pass2=$_REQUEST['txtPass2']; ?> <div id="text" style="position:absolute; overflow:hidden; left:240px; top:280px; width:180px; height:20px; z-index:6"><div class="wpmd"> <div><font face="Arno Pro Caption" color="red"> <? if($pass!=$pass2) { echo("Password values are different"); } ?> </font></div> </div></div> <? } ?> another question,.. is there is a way where in i can manage the events that occur to a control?? like textchange in textboxes. any comments and suggestion is much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/ Share on other sites More sharing options...
cags Posted October 1, 2009 Share Posted October 1, 2009 The only time $variables exist on a form is between the time the user requests that page and the time the PHP parser has finished processing your page. After that point if you have not stored the value in some manner that would allow it to persist the value is lost. <?php if($_REQUEST['command']=='Add') { $pass=$_REQUEST['txtPass']; $pass2=$_REQUEST['txtPass2']; /* At this point you must either: echo $pass back into a hidden input on a form, so the next time the user clicks submit it still exists. store it in a variable that does persist (such as the $_SESSION superglobal array) store it in a flat file system store it in a database */ ?> It's very different to working with a .NET desktop application. In that situation obviously you have access to any variables in scope at all times. With PHP there is no ability to work in that way with the site being a multi-user experience obviously single instances of $variables become irrelevant. The most similar likeness is the $_SESSION array which allows you to store information for each individual on the site. Handling events on input items I believe it possible but it's JavaScript related and alas I know nothing about JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/#findComment-928535 Share on other sites More sharing options...
jon23d Posted October 1, 2009 Share Posted October 1, 2009 Try showing the contents of $_GET or $_POST (<form method='get' or 'post'>) using print_r(); I usually recommend staying away from $_REQUEST, which is rather generic and includes both. As far as managing events for form elements, check out prototype (prototypejs.org). It makes unobtrusive javascript easier, and better allows you to separate display from functionality. Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/#findComment-928612 Share on other sites More sharing options...
mikesta707 Posted October 1, 2009 Share Posted October 1, 2009 what is your forms action set to? is it set to the correct page? using request is perfectly fine, since forms can only be get or post, not both at the same time. Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/#findComment-928617 Share on other sites More sharing options...
jihmantiquilla Posted October 2, 2009 Author Share Posted October 2, 2009 what is your forms action set to? is it set to the correct page? i haven't put any thing to the action method. since i have the event on the button onclick. Try showing the contents of $_GET or $_POST (<form method='get' or 'post'>) using print_r(); I usually recommend staying away from $_REQUEST, which is rather generic and includes both. does it really recommended not to use $_REQUEST. isn't that the print_r() is also the same with echo()?? It's very different to working with a .NET desktop application. In that situation obviously you have access to any variables in scope at all times. With PHP there is no ability to work in that way with the site being a multi-user experience obviously single instances of $variables become irrelevant. The most similar likeness is the $_SESSION array which allows you to store information for each individual on the site. if i into using $_SEESION array where in i can store the values and retrieve it any time. does it always recommended to use $_SESSION in a simple form submission and validation?? Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/#findComment-928797 Share on other sites More sharing options...
jon23d Posted October 2, 2009 Share Posted October 2, 2009 echo and print_r are different, print_r will show you the contents of an array or an object, including $_GET and $_POST. The reason I don't like $_REQUEST is because it contains $_GET, $_POST, and $_COOKIES all in one. I believe that $_GET requests should not allow a user to modify data (isn't this part of the http spec?) Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/#findComment-928817 Share on other sites More sharing options...
jihmantiquilla Posted October 2, 2009 Author Share Posted October 2, 2009 i had also a problem with regards to fetching data's on my sql statement. it seems the value tends to be always '0' knowing that in the sql statement it returns the value 1, and if i try to display it using print_r/echo/ ders no values that is being displayed. do i write my code right?? <? if($_REQUEST['command']=='checkuser') { $username=$_REQUEST['txtusername']; $result=mysql_query("select count(UserName) as User from user where UserName='$username'"); $row=mysql_fetch_field($result) or die(mysql_error()); ?> <div id="text" style="position:absolute; overflow:hidden; left:240px; top:202px; width:180px; height:20px; z-index:6"><div class="wpmd"> <div><font face="Arno Pro Caption" color="red"> <? if($username!="") { if($row->User>=1) { print_r($row->User); //echo("Username already exist"); } else if($row->User==0) { //echo("Username Available"); print_r($row->User); } } else { echo("No values found in username"); } ?> </font></div> </div></div> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/#findComment-928833 Share on other sites More sharing options...
itaym02 Posted October 2, 2009 Share Posted October 2, 2009 I tend to use a library like Zend Framwork when working with forms, abstracts much of the work. Since you are a veteran .net it will be easy for you to get the idea. But, as a basic thing, I used to write my forms like that: <form method='post' action=''> <input type='text' name='myname' value='<?php echo $_POST['myname']; ?>' /> ... ... ... <input type='submit' value='save' /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/#findComment-928836 Share on other sites More sharing options...
jihmantiquilla Posted October 2, 2009 Author Share Posted October 2, 2009 I tend to use a library like Zend Framwork when working with forms upon searching the web. i come up with zend studio as the ide of zend.. i'm using nuSphere right now as my ide. do you recommend zend in developing php. Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/#findComment-928846 Share on other sites More sharing options...
itaym02 Posted October 6, 2009 Share Posted October 6, 2009 I am biased, as I am an ex-Zender, you can guess what I recommend (and what I use). Quote Link to comment https://forums.phpfreaks.com/topic/176192-basic-php-submit-and-validation/#findComment-931273 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.