Form Action "if x go to 1.php else go to 2.php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    Form Action "if x go to 1.php else go to 2.php

    Hi,

    I have to radio buttons and depending on the selection it must eighter insert step2.php or insert.php in the action part of the form.

    Now it's just going to steo2.php

    I also tried elseif ($rado="no") but thats giving the same problem.

    Thans


    [PHP]
    <form id="form1" name="form1" method="post" action="<? $radio=$_POST['radio']; if ($radio="yes")
    echo "step2.php" ;
    else
    echo "insert.php "; ?> ">
    <p>
    <label>
    <input name="radio" type="radio" value="yes" />
    </label>
    </p>
    <p>
    <input name="radio" type="radio" value="no" />
    </p>
    <p>
    <label>
    <input type="submit" name="Submit" value="Submit" />
    [/PHP]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    That is half your script, even only half your form. Where is the submit part of that and where is the script that catches the submitted form?

    In order to help you you must show more code than this little piece.

    Ronald

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Why don't you just have the url of the next page set to the value of the radio button?

      [php]
      <?php
      $radio = @$_POST['radio']; # use @ to supress the 'undefined index' warning.
      ?>
      [/php]
      [code=html]
      <form id=".." action="<?php echo $radio;?>" method="post">
      <input name="radio" type="radio" value="yes.php" />
      <input name="radio" type="radio" value="no.php" />
      <label>
      <input type="submit" name="Submit" value="Submit" />
      </form>
      [/code]

      Comment

      • satas
        New Member
        • Nov 2007
        • 82

        #4
        Originally posted by webandwe
        Hi,
        I have to radio buttons and depending on the selection it must eighter insert step2.php or insert.php in the action part of the form.
        Or you can use JavaScript to change action attribute without reloading page.

        Comment

        • webandwe
          New Member
          • Oct 2006
          • 142

          #5
          Originally posted by ronverdonk
          That is half your script, even only half your form. Where is the submit part of that and where is the script that catches the submitted form?

          In order to help you you must show more code than this little piece.

          Ronald

          Hi have a huge form. I only made this two radion buttons so I can test it on a seperate page

          Comment

          • webandwe
            New Member
            • Oct 2006
            • 142

            #6
            the problem is.

            I have to post the yes or no to th nex page and also insert it into the form action.

            And this is a bit tircky.

            Comment

            • webandwe
              New Member
              • Oct 2006
              • 142

              #7
              Originally posted by satas
              Or you can use JavaScript to change action attribute without reloading page.

              Hi,

              I don't know javascripting. Do you have an example for me?

              Comment

              • arggg
                New Member
                • Mar 2008
                • 91

                #8
                Try
                [code=html]
                <form id=".." action="" method="post">< input name="radio" type="radio" value="yes.php" /><input name="radio" type="radio" value="no.php" /><label><inpu t type="submit" name="Submit" value="Submit" /></form>[/code]

                [code=php]
                <?php
                if ((isset($_POST['radio']) && isset($_POST['Submit']))
                {
                include($_POST['radio']);
                }
                else
                {
                //include the form here
                }

                ?>
                [/code]

                Comment

                • arggg
                  New Member
                  • Mar 2008
                  • 91

                  #9
                  you can try this for javascript

                  [code=html]<form name="RadioForm " action="#"metho d="post"><inp ut name="radio" type="radio" value="yes.php" onClick="javasc ript:actionChec k('yes.php');" /><input name="radio"typ e="radio" value="no.php" onClick="javasc ript:actionChec k('no.php');" /><label><inputt ype="submit" name="Submit" value="Submit"> </form>[/code]

                  [code=javascript]
                  <script language="javas cript" type="text/javascript">
                  function actionCheck($ac tion)
                  {
                  document.RadioF orm.action = $action;
                  }
                  </script>
                  [/code]
                  I have not tested this so i am unsure if it works.

                  Comment

                  Working...