Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/22023-change-_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
Link to comment
https://forums.phpfreaks.com/topic/22023-change-_post/#findComment-98490
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.
Link to comment
https://forums.phpfreaks.com/topic/22023-change-_post/#findComment-98491
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...
Link to comment
https://forums.phpfreaks.com/topic/22023-change-_post/#findComment-98496
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.