Jump to content


Photo

change $_POST


  • Please log in to reply
4 replies to this topic

#1 berilac

berilac
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 September 2006 - 07:36 PM

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... :|

<?
/* 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'];

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

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

Thank you

Michael

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 September 2006 - 07:46 PM

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:
<?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'];
?>

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

Ken

#3 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 25 September 2006 - 07:50 PM

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.

Info: PHP Manual


#4 berilac

berilac
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 September 2006 - 07:54 PM

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...

#5 berilac

berilac
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 September 2006 - 08:01 PM

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...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users