JustANoobie Posted July 1, 2013 Share Posted July 1, 2013 Hello all, I am kind of new to coding but I want to make a php script that is reactive to the information entered by the user. For example if a user inputs the number 1 into a field then xyz will happen on page eg. opening up another input field which wouldn't be visable otherwise. But if the user inputs the number 2 into the field abc will happen on the page. I am asuming this is some kind of a loop. Could someone please help me out or point me in the right direction. Thankyou. Quote Link to comment Share on other sites More sharing options...
DaveyK Posted July 1, 2013 Share Posted July 1, 2013 Its basic form handling. Basically you have something like: <?php if (isset($_POST['submit'])) { if ($_POST['text'] = 'xyz') { // do something } } ?> <form action="/file.php" method="post"> <input type="text" name="text" /> <input type="submit" name="submit" value="Submit" /> </form> Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 1, 2013 Share Posted July 1, 2013 (edited) Sounds to me like you are wanting functionality that requires JavaScript. If you want these changes to be applied dynamically as the user interacts with the form then you need JavaScript. To do this only with PHP, the user must make their entries then submit the form to the server. Edited July 1, 2013 by Psycho Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted July 1, 2013 Share Posted July 1, 2013 I am kind of new to coding but I want to make a php script that is reactive to the information entered by the user. Remember, PHP is only executed on the server, not by a web browser. So, for PHP to do anything with form data it must first get to the server, i.e the form must be submitted. As Psych has stated, if you want the data to be processed as soon as something is entered into the text field (you have termed it reactive), then you require code that the browser understands to get the input data to the server without the user clicking a submit button. PHP can then deal with the data and send a response back. Javascript is needed (AJAX). To make your life simple I would use the JQuery framework. Have a look at this simple tutorial which pretty much does what you are after. http://www.phptutorialforbeginners.com/2013/01/jquery-ajax-tutorial-and-example-of.html Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 1, 2013 Share Posted July 1, 2013 @neil, Based on his request, I'm not sure he even needs AJAX. Unless he a LOT of possible options for the functionality, it sounds as if it could all be done client-side. Quote Link to comment Share on other sites More sharing options...
JustANoobie Posted July 1, 2013 Author Share Posted July 1, 2013 Thankyou neil.johnson that was the exact answer I needed. I will look into jQuery and AJAX. Quote Link to comment 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.