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
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']");

Link to comment
Share on other sites

<?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']}");

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
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.