2013-02-05 4 views
1

PHP 코드에 두 가지 문제점이 있습니다.두 폼 액션을 하나의 폼 PHP

첫 번째는 내가 그것을 리디렉션 페이지에서 얻을 때

$linkorig 

$_POST['formsubmitted'] 

후에 볼 수있는 방법을

변수?

두 번째 질문은 모든 오류 검사가 끝난 후 다른 작업으로 양식을 제출하는 방법입니다.

일부 자바 스크립트 또는 PHP 코드로 가능할 수도 있습니다.

<?php 
    $linkorig=$_POST['link-orig']; // get destination link from redirected page , for excample http://mikrotik.lv -- works fine 
    if (isset($_POST['formsubmitted'])) 
    { 
     // script try login with credentials with <form action="login.php" --- works fine 
     //Error checking ! 
     if (empty($error)) //if not found any errors { 
      // login with credentials and same form but with <form action="other_login.php" --- i dont know how to do :(
     } 
    } 
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <title>Login Form</title> 
    </head> 
    <body> 
     <form name="login" action="login.php" method="post" class="registration_form" onSubmit="return doLogin()" > 
      <input type="hidden" name="dst" value="<?php echo $linkorig; ?>" /> 
      <input type="hidden" name="popup" value="true" /> 
      <fieldset> 
       <legend>Login Form </legend> 
       <p>Enter Your username and Password Below </p> 
       <div class="elements"> 
        <label for="name">Email :</label> 
        <input type="text" id="e-mail" name="username" size="25" value="" /> 
       </div> 
       <div class="elements"> 
        <label for="Password">Password:</label> 
        <input type="password" id="Password" name="password" size="25" /> 
       </div> 
       <div class="submit"> 
        <input type="hidden" name="formsubmitted" value="TRUE" value="OK" /> 
        <input type="submit" value="Login" /> 
       </div> 
      </fieldset> 
     </form> 
     <!-- $(if error) --> 
      <br /><div style="color: #FF8080; font-size: 9px"> </div> 
     <!-- $(endif) --> 
     <script type="text/javascript"> 
      <!-- 
      document.login.username.focus(); 
      //--> 
     </script> 
    </body> 
</html> 
+2

"이 사이트에서는 정상적으로 코드를 삽입 할 수 없습니다."- 질문 입력 옆에 나타나는 * How to Format * 상자를 읽으십시오. – Quentin

+0

JavaScript를 사용하여 Xhr 게시물로 게시물을 올리거나 'curl'을 사용하여 수신 된 게시물을 최초 수신시 서버에서 '전달'할 수 있습니다. 마지막 옵션은 어떻게 '같은 근원'문제를 극복 할 수 있는지입니다. – ficuscr

+0

또는 "post get redirect"에 대한 Google 검색 –

답변

1

당신은 쉽게 2 개의 행동에 대해 하나의 양식을 사용할 수 있습니다 :

<form method='post' action='post.php'> 
<input type='text' name='field1' /> 
<input type='text' name='field1' /> 

<button name='action1'>action1</button> 
<button name='action2'>action2</button> 
</form> 

를 페이지 post.php에 :

모든 당신의 변수, $_POST에서 간단한 조건, 즉 $_POST['field1'], $_POST['field2'], $_POST['action1'] and $_POST['action2'] 사용됩니다

if(isset($_POST['action1'])) { 
    //some code here but still check action2 

    // edit : you can call the action2 with jquery and [ajax][1] 
    // you can use header('location: http://example.com?field1='.$_POST['field1'].'&field2='.$_POST['field1']) to redirect, but no output before using header => see ob_get_clean() if you have any problem. 
} 
else { exit; } //stop it all if action1 failed 

그러나 페이지를 리디렉션하면 더 이상 $ _POST 변수가 없습니다. /page.php?var1=...을 사용하고 $ _POST와 (와) 같이 $ _GET 할 수 있습니다.

+0

아니면 ('other_form.php')를 조건부에 포함 시키거나 수업을 작성하고 양식을 작성하십시오. 거기에서 처리하는 것, 또는 그 질문에 기술 된 별도의 동작을 프로그램 적으로 asinine으로 원하는 곳에서 의미가있는 다른 것. 나는이 문제의 정면이 폼 처리와 사이트의 흐름이라는 개념을 정말로 이해하지 못한다고 생각한다. 여기에서 처리를하지 않은 다음 헤더를 재배치 할 이유가 없습니다. –

+0

음 ..... 보통 좋은 ....! 하지만 action1이 실패하면 모든 것이 멈추지 만 액션 1이 성공하면 액션 2를 수행합니다 –

+0

당신이 필요로하는 것에 대한 답을 편집했습니다 :) –