Reputation: 31
Well my script should looks like that. I have to do it mainly in PHP. Button
add should save data to file, show should read that file and put it into textarea
, delete have to delete chosen line and reset resets everything.
<?php
$plik =fopen("data.dat","a+");
@fputs($plik, $_POST["name"]. " " . $_POST["sname"] . " " . $_POST["adres"] . " " . $_POST["number"] . "<br>" );
fclose($plik);
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name: <input type = "text" name = "name" /><br>
Second Name: <input type = "text" name = "sname" /><br>
Adres: <input type = "text" name = "adres" /><br>
Number: <input type = "text" name = "number" /><br>
<input type = "submit" name="add" value="Add"/>
<input type = "button" name="show" value="Show"/>
<input type = "button" name="reset" value="Reset"/>
<input type = "button" name="delete" value="Delete"/><br>
<textarea id="lista" name="lista" rows="20" cols="40" style="overflow:scroll" readonly="" wrap="off"></textarea>
</form>
</body>
</html>
My script looks like that and i don't know what should i do next. How to add functions to those buttons and how should they look like?
Upvotes: 3
Views: 116
Reputation: 526
I think this should do the job :
<?php
if(isset($_POST['action'])) {
switch($_POST['action']) {
case('Add'): ... break;
case('Show'): ... break;
case('Reset'): ... break;
case('Delete'): ... break;
default: ...
}
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name: <input type = "text" name = "name" /><br>
Second Name: <input type = "text" name = "sname" /><br>
Adres: <input type = "text" name = "adres" /><br>
Number: <input type = "text" name = "number" /><br>
<input type = "submit" name="action" value="Add"/>
<input type = "submit" name="action" value="Show"/>
<input type = "submit" name="action" value="Reset"/>
<input type = "submit" name="action" value="Delete"/><br>
<textarea id="lista" name="lista" rows="20" cols="40" style="overflow:scroll" readonly="" wrap="off"></textarea>
</form>
</body>
</html>
As you can see I have just changed the type of the action buttons to 'submit' and set the same name for all of them. Then in php just test if the action is set, and then choose the correct action to execute. Hope it helps
Upvotes: 2