473,408 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Display Dynamic form on a click event of a Button

ak1dnar
1,584 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
4 7579
xwero
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
1,584 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
xwero
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
1,584 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

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

Similar topics

3
by: DataBard007 | last post by:
My Access 97 database has a form that contains text boxes that display people's names, addresses, phone numbers, etc. The record source is a single table. I created a NextRecord and Previous...
1
by: Jonathan Yong | last post by:
I observe a very weird behavior when dynamically create web control and bind events to it. Create a C# ASP.NET application, Put a PlaceHolder and Textbox onto the Web form, and try with the 4...
1
by: Todd Acheson | last post by:
Attention all Guru's, Let's say I create a control at runtime similar to this: 'this is one button within a loop that creates many buttons Dim ctl as New System.Web.UI.WebControls.Button...
1
by: Steve Booth | last post by:
I have a web form containing a button that when selected adds a user control to a place holder. The user control contains a button. The first time the user control is added the contained button...
4
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up ...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.