june_c21 Posted November 21, 2007 Share Posted November 21, 2007 How to create when enter staff no, it will automatically generate out the name in the same form ? Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/ Share on other sites More sharing options...
MadTechie Posted November 21, 2007 Share Posted November 21, 2007 post to-self this will reload the form with the new data or use AJAX Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395543 Share on other sites More sharing options...
june_c21 Posted November 21, 2007 Author Share Posted November 21, 2007 can you explain more details as i'm new with this. thanks Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395544 Share on other sites More sharing options...
teng84 Posted November 21, 2007 Share Posted November 21, 2007 set your form action to it self <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>"> Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395552 Share on other sites More sharing options...
Distant_storm Posted November 21, 2007 Share Posted November 21, 2007 <?php #check to see if the submit button has been pressed. if (isset($_POST['submit'])) { #if so then output staff number is ... then the value of the textbox sent via post variable echo "Your stff number is..." . $_POST['staff_no']; } else { #if the submit button hasn't been pressed then display the form for the user echo "<form name=\"Form1\" method=\"POST\" action=$_SERVER['PHP_SELF']> Staff Number: <input type=text name=staff_no><br> <input type=submit name=submit value=submit> </form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395569 Share on other sites More sharing options...
zolen Posted November 21, 2007 Share Posted November 21, 2007 just a quick note <form method="post" action=""> will submit to currnt page as well .. and heaps faster to type Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395576 Share on other sites More sharing options...
MadTechie Posted November 21, 2007 Share Posted November 21, 2007 just a quick note <form method="post" action=""> will submit to currnt page as well .. and heaps faster to type try infact you don't need action="" at all, and by removing $_SERVER['PHP_SELF'] your also clear a XSS security hole Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395588 Share on other sites More sharing options...
june_c21 Posted November 21, 2007 Author Share Posted November 21, 2007 that's mean user still need to click on submit button in order for the name to appear? what i want is when user enter their staff no, it automatically generate the name in the same form with staff no. Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395602 Share on other sites More sharing options...
phpQuestioner Posted November 21, 2007 Share Posted November 21, 2007 use mysql to query your database where stuff_no = employees_name then create a hidden field in your form and just echo the variable out for your employees name. something like: <?php // connect to db // select db $mystaff = $_POST['staff_no']; $results = mysql_query("select employee_name from tblName where staff_no='$mystaff'"); while ($mychoice=mysql_fetch_array($results)) { $employee=$mychoice["employee_name"]; echo "<form name=\"Form1\" action=\"". $_SERVER['PHP_SELF'] ."\"> Staff Number: <input type=text name=staff_no><br> <input type=\"hidden\" value=\"$employee\" name=\"currentemployee\"> <input type=submit name=submit value=submit> </form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395606 Share on other sites More sharing options...
june_c21 Posted November 21, 2007 Author Share Posted November 21, 2007 example of the code? Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395608 Share on other sites More sharing options...
phpQuestioner Posted November 21, 2007 Share Posted November 21, 2007 look above - I was still working on it Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395611 Share on other sites More sharing options...
june_c21 Posted November 21, 2007 Author Share Posted November 21, 2007 that mean stil need to click on submit button in order to display the name? Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395613 Share on other sites More sharing options...
phpQuestioner Posted November 21, 2007 Share Posted November 21, 2007 well you have to have the employee enter the number some how - if your not using a form for them to enter their employee number in; then how are they entering it? what i want is when user enter their staff no if your using a link with each employees name in them and a predefine employee number in the link; the just change $_POST to $_GET. $mystaff = $_POST['staff_no']; Link To Employee Form <a href="employeeform.php?staff_no=123">John Doe</a> Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395615 Share on other sites More sharing options...
Distant_storm Posted November 21, 2007 Share Posted November 21, 2007 I think if im correct you mean that you want it so when ever they type their staff number in 54 for example it will display the name of that staff member before they press the button. This would need abit of javascript as it is classed as clientside, unless u used abit of ajax. Quote Link to comment https://forums.phpfreaks.com/topic/78165-solved-getting-data-to-form/#findComment-395831 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.