Jump to content

Unable to redirect my page after submitting a form


joshgom

Recommended Posts

Ive tried using header and form action and my page will not load into another page after submitting !

Any ideas?

 



<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Task2 - App</title>
  <meta name="description" content="The Task2 App">
  <meta name="author" content="SitePoint">
  
</head>
<body>
  
    
    <h1>Task 2 - Web App</h1>
    
    <br><br>
    
    <div class ="submission">
        
        <form action="" method="POST" name='submit'>
            
            
            <label>N:</label>
            <input type="text" name="number-entered" id="number"/>
            <input name="form" type="submit" value="Submit"/>
            <br><br>
            
        </form>
        
    </div> 
    
</body>
</html>

<?php

$number = $_POST['number-entered'];
$form_result = $_POST['form'];




if(isset($form_result)) {
if(($number < 5) || ($number > 25)) {
    
    
    
    echo 'Input out of range';
    
} else {
    

    
    $number = $_POST['number-entered'];
    
    
    foreach ( range(1, $number) as $i ) {  
    $triangle_numbers[] = $i * ( $i + 1 ) / 2;  
        
 } 
    //make a file
    $contents = fopen('gs://a1-task22020.appspot.com/triangular_' .$number. ".txt", "w");
    fwrite($contents,implode(',', $triangle_numbers));
        
    //open the file
    
    $contents = fopen('gs://a1-task22020.appspot.com/' . $content, 'w');
    
    
        
   //re-open the document if you put something in it
    fwrite($contents, $number);
    
    fclose($contents);
    
    
    
}          
}


?>

    









 

Link to comment
Share on other sites

You do not have to redirect the user after submitting a form (handling a POST request).

An easier, and often better, way to show the user whether the data was accepted would be to tell them on the submit location itself.
You could also add a back button to allow the user to safely return to the previous page after reading the status message.

I know this is probably just a basic example, but you should also remember to validate your POST fields.


 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.