joshgom Posted June 20, 2020 Share Posted June 20, 2020 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); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/310971-unable-to-redirect-my-page-after-submitting-a-form/ Share on other sites More sharing options...
requinix Posted June 20, 2020 Share Posted June 20, 2020 If you have problems with some code then you have to post that code. Not the working code. The working code works. Working code doesn't help your non-working code. Quote Link to comment https://forums.phpfreaks.com/topic/310971-unable-to-redirect-my-page-after-submitting-a-form/#findComment-1579038 Share on other sites More sharing options...
NotionCommotion Posted June 21, 2020 Share Posted June 21, 2020 You can redirect using PHP with header("Location: you_disired_url.bla"); or with JavaScript after getting your response. Make sure you understand between server side and client side. Quote Link to comment https://forums.phpfreaks.com/topic/310971-unable-to-redirect-my-page-after-submitting-a-form/#findComment-1579045 Share on other sites More sharing options...
JacobSeated Posted June 21, 2020 Share Posted June 21, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/310971-unable-to-redirect-my-page-after-submitting-a-form/#findComment-1579050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.