| | |
Form load based on condition
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 11
Reputation:
Solved Threads: 0
Hi experts,
I'm extreme beginner in PHP.My problem is that,i've an html page and there's combobox on it,I want to load the form according to the selection of items.
The html page is
and the search.php:
I want to navigate through the page according to the value in the variable v.
Thanks in advance.
I'm extreme beginner in PHP.My problem is that,i've an html page and there's combobox on it,I want to load the form according to the selection of items.
The html page is
html Syntax (Toggle Plain Text)
<form action="search.php" method="post"> <select name="option" size="1"> <option value="1">value1</option> <option value="2">value2</option> <option value="3">value3</option> <option value="4">value4</option> </select> <input type="submit" /> </form>
and the search.php:
php Syntax (Toggle Plain Text)
<?php $v = $_POST['option']; if($v==1) { ?> <form method="get" action="page1.php"></form> <?php } if($v==2) { ?> <form method="get" action="page2.php"></form> <?php } if($v==3) { ?> <form method="get" action="page3.php"></form> <?php } if($v==4) { ?> <form method="get" action="page4.php"></form> <?php } ?>
Thanks in advance.
•
•
Join Date: Jun 2009
Posts: 68
Reputation:
Solved Threads: 10
php Syntax (Toggle Plain Text)
<?php $forms=array( "1"=>"page1.php", "2"=>"page2.php", "3"=>"page3.php"); ?>
build the form:
<form action="" method="post" name="Form">
...
select box <--
...</form>
On submit, check if the posted value is in the array:
php Syntax (Toggle Plain Text)
<?php if ( !empty( $_POST["option"] ) ) { $option = $_POST["option"]; if ( !empty( $forms[$option] ) ) { ?> <form method="get" action="<?php echo htmlspecialchars( $form[$option] ); ?>"></form><?php } else { print "You have selected a non existing option..."; } } ?>
Last edited by djjjozsi; Jun 17th, 2009 at 3:17 am.
•
•
Join Date: Dec 2008
Posts: 11
Reputation:
Solved Threads: 0
Thanks djjjozsi,
but my problem is not solved,
The form doesn't works
but the arrays works.
It doesn't navigate to the page specified in the array
but my problem is not solved,
The form doesn't works
php Syntax (Toggle Plain Text)
<form method="get" action="<?php echo $forms[$option] ; ?>"></form><?php
It doesn't navigate to the page specified in the array
![]() |
Similar Threads
- Changing color of cell in datagridview based on a condition.. CODE not working (VB.NET)
- how to avoid form load again after loading the page in asp.net (ASP.NET)
- How to automatically update temperature on the form load? (Visual Basic 4 / 5 / 6)
- How to load multiple images on the form? (C#)
- form load (Visual Basic 4 / 5 / 6)
- how to load an image to a form (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: selecting data from multiple tables
- Next Thread: simple Insert into 2 tables Gone Wild!
| Thread Tools | Search this Thread |
# 5.2.10 ajax apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date display dissertation dynamic echo echo$_get[x]changingitintovariable... email error file files folder form forms function functions google href htaccess html image images include insert integration ip java javascript joomla ldap legislation limit link local login loop mail memberships menu mlm multiple multipletables mysql mysqlquery oop open paypal pdf persist php problem query radio random recursion regex remote rss script search server sessions sms soap sockets source space spam sql syntax system table tutorial update upload url validator variable video web xml youtube





