Jump to content

How to pass text box value to a php function?


radiations3

Recommended Posts

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.

Link to comment
Share on other sites

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???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.