Jump to content

[SOLVED] Ran into a problem!


TheJoey

Recommended Posts

I have a form which on submit saves information to .txt.

i now want to add form validation but dont know if can sumbit more then one process.

For example

<form action="process.php" method="POST" name="inputform" id="inputform">
Field 1 <br />
<input type="text" size="100" name="field1" />
<br /> 
Field 2 <br />
<input type="text" size="100" name="field2" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

is there another way to make it process validation then if successfull process save file.

?

Link to comment
https://forums.phpfreaks.com/topic/172984-solved-ran-into-a-problem/
Share on other sites

Hi TheJoey,

 

Just add the form validation to the top of the process.php file.  Something like:

 

$field1 = $_POST['field1'];
$field2 = $_POST['field2'];

if(!$field1)
{
$errors .= "\nYou must enter something for field1";
echo $errors;
}

if(!$field2)
{
$errors .= "\nYou must enter something for field2";
echo $errors;
}

if(!$errors)
{
put your process/save text code here
}

 

The above is very basic validation and will check for empty values being posted in both fields.  If errors are found an error message is displayed, if no errors are found the code continues processing.  Get the above working first and then you can build on the validation as required.

 

Hope this helps!

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.