radiations3 Posted March 2, 2012 Share Posted March 2, 2012 Kindly let me know how can i assign values to a php function from any textbox when user clicks on the submit button??? <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> <input type="submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/258091-how-to-pass-text-box-value-to-a-php-function/ Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2012 Share Posted March 2, 2012 Pardon me? Quote Link to comment https://forums.phpfreaks.com/topic/258091-how-to-pass-text-box-value-to-a-php-function/#findComment-1323011 Share on other sites More sharing options...
radiations3 Posted March 2, 2012 Author Share Posted March 2, 2012 lets say there is a php function as function writeName($var) { echo $var; } and the function mentioned above gets value from the for textbox (any textbox of the form) when user clicks on submit button How can i do that?? Quote Link to comment https://forums.phpfreaks.com/topic/258091-how-to-pass-text-box-value-to-a-php-function/#findComment-1323012 Share on other sites More sharing options...
Anon-e-mouse Posted March 2, 2012 Share Posted March 2, 2012 lets say there is a php function as function writeName($var) { echo $var; } and the function mentioned above gets value from the for textbox (any textbox of the form) when user clicks on submit button How can i do that?? If you have a textbox within a form that "POST"s the data then simply need to put something like: <?php // Function... function writeName($var){ return $var; } // Grab it. $var = $_POST['textbox']; // Send it to the function. echo writeName($var); ?> Obviously changing the "textbox" with the actual name of the field. Quote Link to comment https://forums.phpfreaks.com/topic/258091-how-to-pass-text-box-value-to-a-php-function/#findComment-1323034 Share on other sites More sharing options...
radiations3 Posted March 2, 2012 Author Share Posted March 2, 2012 Though my issue is being resolved just kindly answer my one last question is it necessary to redirect our form page to a new page to get the posted value from textbox Can't we do it in the same page like suppose the form for entering values is present at page 'name.php' and when i click on submit either than showing result on a new page its simply shows the output result in the same page that is name.php NAme entered in 'name.php' and also its acho in 'name.php' from the function mentioned above??? Quote Link to comment https://forums.phpfreaks.com/topic/258091-how-to-pass-text-box-value-to-a-php-function/#findComment-1323039 Share on other sites More sharing options...
Anon-e-mouse Posted March 2, 2012 Share Posted March 2, 2012 Though my issue is being resolved just kindly answer my one last question is it necessary to redirect our form page to a new page to get the posted value from textbox Can't we do it in the same page like suppose the form for entering values is present at page 'name.php' and when i click on submit either than showing result on a new page its simply shows the output result in the same page that is name.php NAme entered in 'name.php' and also its acho in 'name.php' from the function mentioned above??? Written in PHP you would need to refresh the page so the data is actually sent in the first place regardless however if you wanted to enter the information into the textbox and send it to the function without refreshing or doing anything to the page you could do it using AJAX. Thats another kettle of fish though. Quote Link to comment https://forums.phpfreaks.com/topic/258091-how-to-pass-text-box-value-to-a-php-function/#findComment-1323049 Share on other sites More sharing options...
radiations3 Posted March 2, 2012 Author Share Posted March 2, 2012 ok thanx!!!! I did it before with javascripting but i was hoping to get it done by using php functions!! Quote Link to comment https://forums.phpfreaks.com/topic/258091-how-to-pass-text-box-value-to-a-php-function/#findComment-1323055 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.