Skip to content

Instantly share code, notes, and snippets.

View Octagon-simon's full-sized avatar
Turning red flags into red tests that pass.

Simon Ugorji (Octagon) Octagon-simon

Turning red flags into red tests that pass.
View GitHub Profile
//syntax
checkFormFields(fields_array, return);
//call the function
$fields = [
"fname" => "First Name",
"lname" => "Last Name",
"email" => "Email Address"
];
if (checkFormFields($fields, true) == 1) {
echo "one or more fields are empty";
} else {
echo "No field is empty";
}
@Octagon-simon
Octagon-simon / form-fields-second-revision
Created October 3, 2021 12:31
How to check if form fields contains a value (!empty) with PHP .
function checkFormFields($fields, $return) {
$requiredFields = []; //init required fields var
$emptyFields = array(); //init empty fields var
foreach ($fields as $field=>$fieldTag) //loop through the array to find the fields and field tags associated
{
array_push($requiredFields, $field); //push required field to the array
<html>
<form method="post">
<input name="fname"> <br>
<input name="lname"> <br>
<input name="email"> <br>
<button type="submit">Submit</button>
</form>
</html>
if ($_POST){
$fields = [
"fname" => "First Name",
"lname" => "Last Name",
"email" => "Email"
];
//call the function
if (checkFormFields($fields, false) == 1) {
$(document).ready(function () {
var url = window.location;
$('ul#navigation a[href="' + url + '"]').parent().addClass('active');
$('ul#navigation a').filter(function() {
return this.href == url;
}).parent().addClass('active');
});
$(document).ready(function () {
var url = window.location;
$('ul.navbar-nav a[href="' + url + '"]').parent().addClass('active');
$('ul.navbar-nav a').filter(function() {
return this.href == url;
}).parent().addClass('active');
});
$(document).ready(function () {
var url = window.location;
$('ul#navbar-nav a[href="' + url + '"]').addClass('active');
$('ul#navbar-nav a').filter(function() {
return this.href == url;
}).addClass('active');
});
@Octagon-simon
Octagon-simon / cookies-part-1.js
Created October 16, 2021 13:49
Set cookies using javascript
document.cookie="username=Octagon";
@Octagon-simon
Octagon-simon / cookies-part-2.js
Created October 16, 2021 13:52
How to retrieve Cookie Values using JavaScript
//Use this function to retrieve cookies by their names
function getCookie(name) { 
 var re = new RegExp(name + "=([^;]+)"); 
 var value = re.exec(document.cookie); 
 return (value != null) ? unescape(value[1]) : null; 
}
//Call the function
getCookie('username');