Using php with <input>

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Graham2107
Forum Newbie
Posts: 2
Joined: Fri Jul 25, 2008 3:15 am

Using php with <input>

Post by Graham2107 »

I would like to use some php script in the body of a php document that changes the inclusion of a <div> or a <table> depending on the users input.

For instance:

<input name=user_input value="<?php echo $user ?>" etc. >

if ($user == "Fred")
{include ('Fred_Div.php');}
if ($user == "Graham")
{include ('Graham_Div.php');}

Where Fred_Div.php and Graham_Div.php have been predefined as simple HTML code snippets stored as .php files

I have tried using $_COOKIE but this doesn't seem to work. Perhaps I need to pre-define ?
abhikerl
Forum Newbie
Posts: 9
Joined: Wed Jun 04, 2008 2:07 am
Location: Mauritius

Re: Using php with <input>

Post by abhikerl »

Hi, can you explain a bit more clearly. I understand your explanation but your code doesn't seem right according to what you want.

Firstly correct:

<input name="user_input" value="<?php echo $user ?>" etc. >

Now, you said, the changes will be according to the user input, but you have already defined the input by saying "value="<?php echo $user ?>". This line will display fred or graham in the textbox.

It's better that you submit the form where it will go to a process page.
Graham2107
Forum Newbie
Posts: 2
Joined: Fri Jul 25, 2008 3:15 am

Re: Using php with <input>

Post by Graham2107 »

Perhaps I didn't explain myself totally.

<input name="user_input" value="0" etc. >

if user_input equals "Fred" then include xyz.php and if user_input equals "Graham" then include abc.php

This is, the form actually changes format, depending on what the user_input is.

Does that make more sense ?
abhikerl
Forum Newbie
Posts: 9
Joined: Wed Jun 04, 2008 2:07 am
Location: Mauritius

Re: Using php with <input>

Post by abhikerl »

Ya I understand. First, you cannot change your display simply by entering data in a textbox. You should summit the data, which means there should be a submit button and another page.

Or if you don't want to use a submit button, then you should use ajax.
http://www.tizag.com/ajaxTutorial/
Post Reply