472,804 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 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 7522
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,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.