467,878 Members | 1,261 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,878 developers. It's quick & easy.

Display Dynamic form on a click event of a Button

ak1dnar
Expert 1GB
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
  • viewed: 7162
Share:
4 Replies
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 1GB
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
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 1GB
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.

Similar topics

1 post views Thread by Jonathan Yong | last post: by
1 post views Thread by Todd Acheson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.