Forums

On Submit Befor Send

FlyingEagle 20 Jun, 2008
I am not the best coder in PHP but here is what I am trying to do.

I created a form and when they click submit I want to run some code before the e-mail and data is saved. What I need to do is check the database to see if what they are entering already exists. If it exists it will not post the data and tell them it's already been entered. If it does not exist it will continue and post the data to the DB.

My issue is that the form submit does not continue with posting the data, how do I make this happen? In other words if the data is not in the DB already how do I continue on the submit proccess so that the data is placed in the DB.

Thanks

Form code:
<?php

global $my, $mosConfig_live_site, $database;
?>
<fieldset>

<legend>Enter Your Odomitor Reading</legend>
<label for="enterdate">Date: <?php echo date("m/d/Y")?></label>
<input type="hidden" name="enterdate" id="enterdate" value="<?php echo date("m/d/y")?>" readonly="readonly" />
<br />
<label for="name">Name: <?php echo $my->name ?></label>
<input name="name" id="name" value="<?php echo $my->name?>" readonly="readonly" type="hidden" />
<br />
<label for="millage">Current Odomitor Reading: </label>
<input type="text" size="6" name="millage" />
</fieldset>
<input type="submit" value="send"  />
On Submit Code - Before Send:
<?php

$sql = "SELECT millage from #__chronoforms_1 where name like '".$_POST['name']."'";
$database->setQuery($sql);
$rows = $database->loadObjectList();

foreach($rows as $record)
{
 if ($record->millage == $_POST['millage'])
 {
 echo "You have already posted this odomitor reading.";
 }
}?>
GreyHead 21 Jun, 2008
Hi FlyingEagle,

I don't see whay this would not go on to save the data . . .

Do you have a redirect url? If so I wonder if you've got the buggy version of chronocontact,php that won't save and email???

To stop the data being saved you'll need to add an conditional 'if' check to the Autogenerated code. You can set a '$save_entry' variable in the loop you have above
$save_entry = true;
foreach($rows as $record) { 
  if ($record->millage == $_POST['millage']) { 
    $save_entry = false;
    echo "You have already posted this odometer reading."; 
  } 
}
and check for that later:
if ( $save_entry ) {
. . . // normal autogenerated code
}
Bob
This topic is locked and no more replies can be posted.