2012-05-17 2 views
8

조금 문제가 있습니다. 양식을 제출 한 후 페이지를 새로 고침하고 싶습니다. <form method="post" action="action=""">에서양식 제출 후 페이지 새로 고침

<form method="post" action=""> 
    <textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea> 
    <br /> 
    <input type="submit" value=" Update " id="update_button" class="update_button"/> 
</form> 
+2

귀하의 목표는 무엇입니까? – Shyju

+0

이것이 기본 동작이 아닙니까? 왜 그 가치를 당신의 행동에 넣었습니까? 나는 그것이 잘못되었다고 생각한다. – davidbuzatto

+0

예 그것의 실수는 –

답변

0

당신은 아마 사용할 수 있어야한다 :

<form method="post" action=" " onSubmit="window.location.reload()"> 
+0

나는 이것을 이미 시도했지만 페이지는 상쾌하지 않다 : S –

0

폼 그 자체을 제출 원하는? 그런 다음 "action"매개 변수를 비워 두십시오.

좋아 :이 페이지에 양식을 처리 할 경우

<form method="post" action="" />

, 당신은 제대로 제출 및 확인 여부를 테스트하는 형태 또는 세션 데이터에 어떤 메커니즘이 있는지 확인 빈 양식을 처리하려고하지 않습니다.

양식이 작성되어 제출되었지만 유효하지 않은 경우 다른 메커니즘으로 결정할 수 있습니다. 나는 보통 세션 변수와 일치하는 숨겨진 입력 필드를 사용하여 사용자가 제출을 클릭했는지 아니면 처음 페이지를로드했는지 결정합니다. 매번 고유 한 값을 제공하고 세션 데이터를 동일한 값으로 설정하면 사용자가 제출을 두 번 클릭하면 중복 제출을 피할 수 있습니다.

4

양식을 동일한 페이지에 제출하려면 양식 속성에서 action을 제거하십시오. 페이지를 다시로드하거나 다른 파일에서 양식을 제출 한 후 페이지를 재 지정하려면

<form method="POST" name="myform"> 
<!-- Your HTML code Here --> 
</form> 

그러나, 당신은 php에서이 함수를 호출는 0 초 단위로 페이지를 리디렉션합니다. 당신이 당신의 전체 페이지에 header

function page_redirect($location) 
{ 
    echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">'; 
    exit; 
} 

// I want the page to go to google. 
// page_redirect("http://www.google.com") 
+0

나는이 코드를 양식 코드 다음에 사용해야 만한다? –

+0

제출을 클릭 한 후 페이지를 새로 고치려면 HTML에서 첫 번째 태그를 사용하십시오. 제출하려는 페이지를 클릭 한 후 원하는 경우 두 번째 페이지를 사용하십시오. 그것은 당신의 선택입니다. – Othman

2
<form method="post" action=""> 
    <table> 
    <tr><td><input name="Submit" type="submit" value="refresh"></td></tr> 
    </table> 
    </form> 

<?php 
    if(isset($_POST['Submit'])) 
    { 
    header("Location: http://yourpagehere.com"); 
    } 
?> 
10
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!-- notice the updated action --> 
<textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea> 
<br /> 
<input name="submit_button" type="submit" value=" Update " id="update_button" class="update_button"/> <!-- notice added name="" --> 
</form> 

을 사용하기 전에 어떤 내용이없는 있는지 확인하려는 경우 또한, 당신은 header을 사용할 수 있습니다,이

을 가질 수
<?php 

// check if the form was submitted 
if ($_POST['submit_button']) { 
    // this means the submit button was clicked, and the form has refreshed the page 
    // to access the content in text area, you would do this 
    $a = $_POST['update']; 

    // now $a contains the data from the textarea, so you can do whatever with it 
    // this will echo the data on the page 
    echo $a; 
} 
else { 
    // form not submitted, so show the form 

?> 

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!-- notice the updated action --> 
<textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea> 
<br /> 
<input name="submit_button" type="submit" value=" Update " id="update_button" class="update_button"/> <!-- notice added name="" --> 
</form> 

<?php 

} // end "else" loop 

?> 
26

에만 사용

echo "<meta http-equiv='refresh' content='0'>"; 

직후에 삽입 쿼리 전에} 예를 들어이 도움이

if(isset($_POST['submit'])) 
     { 
SQL QUERY---- 
echo "<meta http-equiv='refresh' content='0'>"; 
} 
+1

이것은 나를 위해 일한 유일한 해결책입니다. –

+0

좋은이게 정말 도와 줬어! – Tomm

0
//insert this php code, at the end after your closing html tag. 

    <?php 
    //setting connection to database 
    $con = mysqli_connect("localhost","your-username","your- 
    passowrd","your-dbname"); 

    if(isset($_POST['submit_button'])){ 

    $txt_area = $_POST['update']; 

     $Our_query= "INSERT INTO your-table-name (field1name, field2name) 
        VALUES ('abc','def')"; // values should match data 
       // type to field names 

     $insert_query = mysqli_query($con, $Our_query); 

     if($insert_query){ 
      echo "<script>window.open('form.php','_self') </script>"; 
      // supposing form.php is where you have created this form 

      } 



    } //if statement close   
    ?> 

희망.

관련 문제