Page 1 of 1

Using php with <input>

Posted: Fri Jul 25, 2008 3:24 am
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 ?

Re: Using php with <input>

Posted: Fri Jul 25, 2008 3:46 am
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.

Re: Using php with <input>

Posted: Fri Jul 25, 2008 4:15 am
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 ?

Re: Using php with <input>

Posted: Fri Jul 25, 2008 7:51 am
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/