Jump to content

Recommended Posts

The below is flagging errors #3 and #9. Error #3 is being thrown even though the emails match.

 

<?php
session_start();
$_SESSION['submitted']="yes";
$error=$_GET['error'];
$date_rma="5/10/2011";
$content='
<div class="content_text">
<div class="content_header">Request RMA Number</div>
<p>Enter the information you used on PayPal, that you completed your order with. The information must match, or a RMA Number will not
be issued.</p>
<form action="./rma_process.php" method="post">
<p><label>Name:</label> <input type="text" name="name" size="30" 
value="'.(isset($_SESSION['name']) ? $_SESSION['name'] : '').'" />';
if($error[0]==1){ $content.=' <span class="red bold">This field is required.</span>'; }
$content.='</p>
<p><label>E-Mail Address:</label> <input type="email" name="email" size="35" 
value="'.(isset($_SESSION['email']) ? $_SESSION['email'] : '').'" />';
if($error[1]==1){ $content.=' <span class="red bold">This field is required.</span>'; }
$content.='</p>
<p><label>Confirm E-Mail Address:</label> <input type="email" name="confirm_email" size="35" 
value="'.(isset($_SESSION['confirm_email']) ? $_SESSION['confirm_email'] : '').'" />';
if($error[2]==1){ $content.=' <span class="red bold">This field is required.</span>'; }
if($error[3]==1){ $content.=' <span class="red bold">E-Mail addresses do not match.</span>'; }
$content.='</p>
<p><label>Phone Number:</label> <input type="text" name="phone" size="15" 
value="'.(isset($_SESSION['phone']) ? $_SESSION['phone'] : '').'" /> 
Ext. <input type="text" name="ext" size="4" 
value="'.(isset($_SESSION['ext']) ? $_SESSION['ext'] : '').'" />';
if($error[4]==1){ 
$content.=' <span class="red bold">A properly formatted phone number is required.</span>'; }
$content.='</p>
<p><label>Date of Purchase (MM/DD/YYYY):</label><input type="text" name="month" size="2" maxlength="2" 
value="'.(isset($_SESSION['month']) ? $_SESSION['month'] : '').'" />
<input type="text" name="day" size="2" maxlength="2" 
value="'.(isset($_SESSION['day']) ? $_SESSION['day'] : '').'" /> 
<input type="text" name="year" size="5" maxlength="4"  
value="'.(isset($_SESSION['year']) ? $_SESSION['year'] : '').'" />';
if($error[5]==1 || $error[6]==1 || $error[7]==1){ 
$content.=' <span class="red bold">A properly formatted date is required.</span>'; }
$content.='</p><p><label>List the Products you wish to return. Sperate with a comma. <br />Use either the whole product name, or the GHP# Product Code:</label>';
if($error[8]==1){ $content.=' <span class="red bold">This field is required.</span>'; }
$content.='<textarea name="products_returning" rows="10" cols="60">
'.(isset($_SESSION['products_returning']) ? $_SESSION['products_returning'] : '').'';
$content.='
</textarea>
<input type="hidden" name="submitted" value="yes" />
</p>
<p><input type="submit" value="Submit" name="Submit" /></p>
</form>
</div>
';
?>

 

<?php
session_start();
$name = $_POST['name'];
$_SESSION['name']=$name;
if($name==""){
$error0=1;
}
else{
$error0=0;
}

$email = $_POST['email'];
$_SESSION['email']=$email;
if($email==""){
$error1=1;
}
else{
$error1=0;
}

$confirm_email = $_POST['confirm_email'];
$_SESSION['confirm_email']=$confirm_email;
if($confirm_email==""){
$error2=1;
}
else{
$error2=0;
}

if($email!=$confirm_email){
$error3=1;
}
else{
$error3=0;
}

$phone = $_POST['phone'];
$_SESSION['phone']=$phone;
if($phone==""){
$error4=1;
}
else{
$error4=0;
}

$ext = $_POST['ext'];
$_SESSION['ext']=$ext;

$phone = $phone.' Ext.'.$ext;

$month = $_POST['month'];
$_SESSION['month']=$month;
if($month=="" || !is_numeric($month)){
$error5=1;
}
else{
$error5=0;
}

$day = $_POST['day'];
$_SESSION['day']=$day;
if($day=="" || !is_numeric($day)){
$error6=1;
}
else{
$error6=0;
}

$year = $_POST['year'];
$_SESSION['year']=$year;
if($year=="" || !is_numeric($year)){
$error7=1;
}
else{
$error7=0;
}

$date="".$month."/".$day."/".$year."";

$products_returning = $_POST['products_returning'];
$_SESSION['products_returning']=$products_returning;
if($products_returning==""){
$error8=1;
}
else{
$error8=0;
}

if($_SESSION['submitted']=="yes"){
$error9=0;
}
else{
$error9=1;
}


$error="".$error0."".$error1."".$error2."".$error3."".$error4."".$error5."".$error6."".$error7."".$error8."".$error9."";

if($error!=="0000000000"){
header("Location: ./index.php?returns=rma&error=".$error0."".$error1."".$error2."".$error3."".$error4."".$error5."".$error6."".$error7."".$error8."".$error9."");
}
else{
header("Location: ./index.php?returns=submitted");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/237755-form-error-checking-issue/
Share on other sites

You did not declare $_SESSION['submitted']. I doubt you want to store a $_SESSION['submitted'], so I would suggest trying

 

if($_POST['submitted']=="yes"){

 

Instead of

if($_SESSION['submitted']=="yes"){

 

I did in the first page:

 

$_SESSION['submitted']="yes";

 

Just below session_start();

 

I'm trying to use hidden inputs as little as possible. I removed the <input type="hidden"> tag.

Tested your code and it works fine... only had to add in a few lines of code to properly parse the $_GET['error'] into the $error array. I suppose you have omitted that from the code you posted?

 

Can you try var_dump($_SESSION), or more specifically $_SESSION['submitted'] in the error checking portion?

Tested your code and it works fine... only had to add in a few lines of code to properly parse the $_GET['error'] into the $error array. I suppose you have omitted that from the code you posted?

 

Nope, the $error variable is working as I have it in the code posted.

 

 

var_dump returns:

 

array(9) { ["name"]=> string(4) "test" ["email"]=> string(16) "test@exmaple.com" ["confirm_email"]=> string(16) "test@example.com" ["phone"]=> string(12) "123123123123" ["ext"]=> string(0) "" ["month"]=> string(2) "12" ["day"]=> string(2) "12" ["year"]=> string(4) "1212" ["products_returning"]=> string(46) "asdfasdfsadfswdfsadfasfasfsafdasdfasdfasdfasdf" } 

Found the issue...

 

I killed the session on index.php at the bottom of the page... rma.php (the one with the form) is included into index.php. Index.php is basically the layout of the site, while rma.php is the content for ?returns=rma. So $_SESSION['submitted'] was being killed before it was even sent to the next page.

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.