Jump to content

Reactive website


JustANoobie

Recommended Posts

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.

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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 by Psycho
Link to comment
Share on other sites

 

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

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.