Jump to content

help with form validation


shane85

Recommended Posts

hey guys

 

im trying to do some form validation but running into a problem....I have 2 pages,

 

edit_prospect.php

and

edit_prospect2.php

 

my form is on edit prospect.php but im viewing records with it so its always like edit_prospect.php?prospect_id=30 or something like that...when the form is submitted, it submits to edit_prospect2.php

 

on edit_prospect2.php I have the following code

 

<?php

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

// the if statements and error messages
if($firstname == '')
{
   $errmsg_arr[] = 'First name missing';
   $errflag = true;
}
if($lastname == '') {
   $errmsg_arr[] = 'Last name missing';
   $errflag = true;
}
if($contact_next == '') {
   $errmsg_arr[] = 'You must enter a date to contact this prospect next';
   $errflag = true;
}

//If there are input validations, redirect back to the registration form
if($errflag)
{
   header("location: edit_prospect.php?prospect_id=38"); // for testing purposes im just testing the 38 record but eventually it will jus tbe to 
                                                                                          // edit_prospect.php?prospect_id=(variable for prospect_id here)
}

 

then on edit_prospect.php I just have the following

 

<?php
echo $errmsg_arr;
?>

 

now obviously the form submits to it when there is an error, but it dosnt display what the error is. If  u fill in the fields, it goes to the proper page. What is wrong?

Link to comment
https://forums.phpfreaks.com/topic/197721-help-with-form-validation/
Share on other sites

also, I tried changing it from prospect_id=38 to putting in the variable and I get this error

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in edit_prospect2.php on line 72

 

line 72 is

 

header("location: edit_prospect.php?prospect_id=$arrEntry['prospect_id']");

<?php
session_start();
//Array to store validation errors
$_SESSION['errmesg'] = array();

 

Simple enough using sessions from then on. It'll allow you to keep the variable on any page provided you place session_start in it.

 

----

 

header("location: edit_prospect.php?prospect_id=$arrEntry['prospect_id']");

 

It should be:

header("Location: edit_prospect.php?prospect_id={$arrEntry['prospect_id']}");

 

ahhh....I jumped the gun.....

 

using this

 

header("Location: edit_prospect.php?prospect_id={$arrEntry['prospect_id']}");

 

submits the page and gives the error, however the record for $arrEntry['prospect_id'] doesnt print in the url, so it doesnt reload that form

hmm I tried putting this in the page cause I didnt know if it was getting the variable

 

$prospect_id="'.$_GET['prospect_id'].'";

 

and now I can see the prospect_id in the header, but im getting this msg

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in edit_prospect2.php on line 65...and line 65 is the above code

I took out the double quotes so line 65 is as follows

 

$prospect_id='.$_GET['prospect_id'].';

 

and I get the following error

 

Parse error: syntax error, unexpected T_STRING in edit_prospect2.php on line 65

 

If you look at the syntax highlighting it tells you, You should get a proper IDE/notepad that automatically highlights syntax, such as notepad++ / VIM.

 

$prospect_id = $_GET['prospect_id'];

 

Or if you wanted:

header("Location: edit_prospect.php?prospect_id={$_GET['prospect_id']}");

 

Which should work fine. Remember syntax regarding quotes, and escaping them. It's one of the frontline debugging tasks!

Archived

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

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