By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,965 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,965 IT Pros & Developers. It's quick & easy.

Display Dynamic form on a click event of a Button

ak1dnar
Expert 100+
P: 1,584
I need to display a form dynamically.
First i load the page and at that time Login button will display.
Nothing else.
If some clicks the Login button, then only I want to display the Form.
So what will be the best solution for this.

[PHP]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body><input name="login" type="button" id="Login" value="Login" />
<form id="form1" name="form1" method="post" action="login.php">
<p>
<input type="text" name="textfield" />
<input type="text" name="textfield2" />
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
[/PHP]
Feb 20 '07 #1
Share this Question
Share on Google+
4 Replies


P: 99
I need to display a form dynamically.
First i load the page and at that time Login button will display.
Nothing else.
If some clicks the Login button, then only I want to display the Form.
So what will be the best solution for this.

[PHP]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body><input name="login" type="button" id="Login" value="Login" />
<form id="form1" name="form1" method="post" action="login.php">
<p>
<input type="text" name="textfield" />
<input type="text" name="textfield2" />
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
[/PHP]
the most easy way in php is to use an if statement


[PHP]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="login.php">
<?php if($_POST['login']){ ?>
<p>
<input type="text" name="textfield" />
<input type="text" name="textfield2" />
<input type="submit" name="Submit" value="Submit" />
</p>
<?php }else{ ?>
<input name="login" type="submit" id="Login" value="Login" />
<?php } ?>
</form>
</body>
</html>
[/PHP]
Feb 20 '07 #2

ak1dnar
Expert 100+
P: 1,584
Its sorry to say that this is not working as i need, please read the original post carefully, i have mentioned my requirement there.

When i first load the page login button will display.(Not the form)
Then when i press the Login button form area will display, then i can submit it for processing.

Anyway i made it. But few more questions.Here in my coding when i press the Login button Form is getting. But since i am using PHP self execute, the entire page area will reload..

Is there any way to avoid this. I mean with out reloading the entire page cant i load Just only the form to the same page.

[PHP]
<?
if ($_POST['login'])
{
$form = '<form id="form1" name="form1" method="post" action="login.php">
<input type="text" name="textfield" />
<input type="text" name="textfield2" />
<input type="submit" name="Submit" value="Submit" />
</form>';
}
?>
<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>



<body>

<form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
<input name="login" type="submit" id="Login" value="Login" />
</form>
<?php echo $form; ?>
</body>

</html>
[/PHP]
Feb 21 '07 #3

P: 99
Your code is the same as mine only you let the login button on the page, you replaced the login form to the code and you changed the action of the form tag .

Why would you let the login stay there without use? Or are you thinking about toggleing the form by that button.

Putting the html code in php code to display it is considered bad practice in these times of templated website design.

To answer your question: it's not possible to do this without a page reload because php is a server language. It always needs a roundtrip to the server to make things work. that's why javascript and the xmlhttp object get so much attention these days.

code with toggleing
[PHP]
<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>



<body>

<form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF; ?>">

<?php
// to be sure you could replace the if statment with
// isset($_POST['login']) && $_POST['login'] == 'Login'
if($_POST['login']){ ?>
<p><input name="hide" type="submit" id="Login" value="Hide Login" /> </p>
<p>

<input type="text" name="textfield" />

<input type="text" name="textfield2" />

<input type="submit" name="Submit" value="Submit" />

</p>

<?php }else{ ?>

<p><input name="login" type="submit" id="Login" value="Login" /> </p>

<?php } ?>

</form>

</body>

</html>
[/PHP]
Feb 21 '07 #4

ak1dnar
Expert 100+
P: 1,584
OK thanks.Looks like i have to go for a Ajax Solution for this.
Thank you very much again.
Feb 21 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.