Hi Can anyone help me, I am trying to create a textfield with a button so when a user enters a value into that field and clicks the button the value is stored in a variable on the same page. Any help appreciated Thanks
How exactly are you wanting the value stored on the page? In a hidden field, in a javascript variable, through sessions?
When the form is submitted to your processing script, just use $_SESSION to save the variable http://www.w3schools.com/PHP/php_sessions.asp There's really nothing to it
Its the actual method of the processing script Im struggling with. Getting the variable from the form.
Create a simple GET/POST form (if you don't know how to do this then you're going to need to lookup some tutorials) then use $_SESSION['your_session_var_name_here'] = $_GET['text_field_id_here']; PHP: use $_POST if you use the POST method for your form
Make sure you use the $_POST function and not the $_GET function since you are using a textfield, where you probably will have lots of characters. $_GET has a limit of characters, and they are seen in the url on top of the page, which is not so nice - therefore, use $_POST in this case! Good luck!
So if I passed the variable from the textfield field from page 1 to page 2 how would I store that variable so if i went to say for example page 3 upon returning to page 2 my variable would still be stored? Thanks
Don't use the session variable because that will piles up into client's memory. When you want to retrieve value from a from, do like this Put this HTML code in your site <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <input type="text" name="txtField"/> <br/> <input type="submit" name="submit" value="Click here to submit"/> </form> Put this PHP code in the head of the site <?php if (isset($_POST['txtField']) && !empty($_POST['txtField']) { //Do sth here } ?> That's how you want to retrieve the value when a user click on a button and stay in the same page Now, if you want the value to be passed to page 2, in the action property of HTML form, replace it with the URL of page 3 If you want a value to be consistent through page 1, 2, and 3, one way is stored in session and another way is stored in the database. Normally, you will create a class with a distinct ID and then on page 1 you save your variable into your class then in page 2 and 3 just load this class and retrieve the value.
in page1 store your session variable after you submit and you can then call it in page 2 and 3. make sure all your pages have session_start(); at the beginning
after reading through this I am doing mostly the same thing. I have a form page that posts to another where I am converting the "POST" data to session varriables so I can use it in the creation of an XML string. I convert the post data using the following: function StripSpecChar($val) { return (preg_replace('/[^a-zA-Z0-9" ".@\:\/_]/','', $val)); } //Convert each POST data field from the form to PHP Session state foreach ($_POST as $key => $val) { $_SESSION[$key] = StripSpecChar($val); } PHP: So what this is doing is 1) taking out the special characters that I don't want in my db. 2) converting anything that came over as a "POST" value in to a $_SESSION var. Exp: <form method="post" name="form1" id="form1" action="my_process.php"> <input name="phone" type="text" value=""> <input type="submit" name="submit"> </form> HTML: and phone="555-55-5555" when it hits my process page the first function strips the "-" from the number the next function takes the "POST" phone and value and converts to $_SESSION['phone']=555555555; and I can call it where I need to use it by doing: print $_SESSION['phone']; Dont know if this is what you were after but just trying to help.