Jump to content

Archived

This topic is now archived and is closed to further replies.

berilac

change $_POST

Recommended Posts

Hi,
I have an html form included in a php file.
when it submits it uses post to change a variable from 0 to 1, so that if any errors occur it will display relevant error messages. To briefly explain, when its set to 0, only the form is shown and no error checks are made, but when they click submit it changes it to 1 and allows the php to make error checks. (Sorry if this is badly explained - im new to php)

however, on clicking refresh, i would like the variable to be reset to 0 so that no error checks are made, but i cant change the $_POST value back to 0.

Heres the beginning to the code, which hopefully will clarify where ive made a complete idiot of myself with my bad coding... :|

[code]
<?
/* Load html backplate */
include ("../html/head.html");

include 'db.php';

/* Check that the user has submitted their details */
$submitcheck = 0;
$submitcheck = $_POST['submitcheck'];

if ($submitcheck == 0)
{
  /* load form */
  include ("../html/regfrm.html");
}
else
{
$_POST['submitcheck'] = 0;
  // Define post fields into simple variables
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $email_address = $_POST['email_address'];
  $username = $_POST['username'];
  $website = $_POST['website'];
  $info = $_POST['info'];
[/code]

Please, if anyone can help, it would be amazing.

Just ask if i need to explain myself better, etc.

Thank you

Michael

Share this post


Link to post
Share on other sites
The $_POST array is recreated each time the form is submitted (that includes on a refresh), so setting a value in $_POST and expecting the form to to reflect the change will not work.

What you probably want to used here is a session variable. Try something like this:
[code]<?php
session_start();
/* Load html backplate */
include ("../html/head.html");

include 'db.php';

/* Check that the user has submitted their details */
$submitcheck = (isset($_SESSION['submitcheck']))?$_SESSION['submitcheck']:false;


if (!isset($_POST['submit']))
{
  /* load form */
  include ("../html/regfrm.html");
}
else
{
$_SESSION['submitcheck'] = true;
  // Define post fields into simple variables
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $email_address = $_POST['email_address'];
  $username = $_POST['username'];
  $website = $_POST['website'];
  $info = $_POST['info'];
?>[/code]

This assumes that the Submit button on the form is named 'submit'.

Ken

Share this post


Link to post
Share on other sites
I think you're going about this wrong.  If this is for verification, you need to put your processing part above the form in case the processing fails and you need to show the form again.  Also, I'm not sure why you want to change the $_POST value.  That's not going to do much good for you.

Share this post


Link to post
Share on other sites
thank you to both of you.

Like i said, i am extremely new to php and basically used some tutorials to help build a kind of test website. I then alter the code as much as i can to make it work for me as well as learn to understand it...

i will try to implement a session varaible instead. Sounds a much better option, one i hadnt explored as i was using the knowledge id gained thus far...

Share this post


Link to post
Share on other sites
tried it and it works but it doesnt reset the session variable i dont think, as when you click refresh, it shows the error check messages...

Share this post


Link to post
Share on other sites

×

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.