1

I have 2 FORMS on a single page, One below the other.

I would like to have such that second form should be always in disable mode.

and Once the first form submit button is pressed and validated second should get activated to enter the data in it.

Is there anything in PHP which can help me on this

4
  • if statement could help, I belive Commented Jan 24, 2013 at 9:46
  • I understand if statement, but second form should be in disabled mode (like inactive and your cannot enter data in it) Commented Jan 24, 2013 at 9:47
  • I think he wants to show both forms at once but with second "not available" Commented Jan 24, 2013 at 9:47
  • yes Edga, you are right!! but I want to know anything is there only in PHP which can help me Commented Jan 24, 2013 at 9:51

5 Answers 5

2

You have 2 ways:

1) send validation of first form using ajax, and, if you receive 'true', enable second form.

2) make a POST from first form, if everything is good, set "validated" to 'true' and reload the same page. In the second form "enabling" must be only if you have $validated = true;

Sign up to request clarification or add additional context in comments.

3 Comments

HI Andrej, Thanks for ur valuable response, but i do not want to use ajax, its only PHP i need
ajax - it's PHP-too. Try to go second way i described, it don't needs ajax.
Andrej, I'll try out 2nd one
1

The logic below should help you out as a starting point:

<form method="post">
    <input type="text" name="name" />
    <input type="submit" name="form1" value="Proceed" />
</form>

<form method="post">
    <input type="text" name="email"<?php if(!isset($_POST['form1'])) { echo ' disabled="disabled"'; } ?> />
    <input type="submit" name="form2" value="Submit"<?php if(!isset($_POST['form1'])) { echo ' disabled="disabled"'; } ?> />
</form>

Of course, it would be much more reliable to use either AJAX to validate the first form, or to have the forms appear on separate pages.

Comments

0
<?php
    if(isset($_POST['next'])) {
        if($_POST['name']!="") {
            $disabled = "";
            $val = $_POST['name'];
        } else {
            $disabled = " disabled='disabled'";
            $val="";
        }
    } else {
        $disabled = " disabled='disabled'";
        $val="";
    }

?>

<html>
    <head>
    <title></title>
    </head>
    <body>
        <form id="frm1" name="frm1" method="POST" action="">
            <label>Name</label><input type="text" id="name" name="name" value="<?php echo $val;?>"/>
            <input type="submit" name="next" id="next_frm" value="Next"/>
        </form>
        <form name="frm2" id="frm2" method="POST" action="">
            <label>Address</label><input type="text" name="address" id="address" value="" <?php echo $disabled;?>/>
            <input type="submit" name="save" id="save" value="Save" <?php echo $disabled;?>/>
        </form>
    </body>
</html>

This is somewhat you were looking for ,I hope

2 Comments

Hi Roger, Thanks for ur response, but i do not want to call jquery
@Parab: Modified . you can check
0

You can do it by setting a class on all inputs within second form and set them as disabled of course someone who knows a bit of javascript will be able to change it.

So you can do it as your visual layer, but then check in PHP as well if second form can be passed in case someone wanted to sneak something in.

More complicated approach would be to show images that look like form fields and only change them to inputs where the first form is submitted. That can be done on client or server side

So in reality you will have 3 forms, but one would be "fake"

Comments

0

Thats simple just use if else condition.

// this if condition checks whether the form 1 is submitted or not. If form1 is submitted than form 2 is displayed else form1 wil only be displayed     
if(isset($_POST['submit']))
{
    //Display your form 2.
}

else
{
     //Display your form1.
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.