Form Submit Button - Change the action page each time submitted - javascript

I have a form with a submit button that when pressed it emails the contents to a single email address. The email is then manually forwarded to one of 3 people on a rota system.
Is there any way that the submit button could work so that when the first site visitor clicks it the inquiry goes to staff member 1, when the next one does it the inquiry goes to staff member 2 when the next one does it it goes to staff member 3 and then back to staff member 1 when the next one does it.
Any help would be greatly appreciated.

Make a column in database for current active_member
set 0 default value.
get first staff member from database with column active_member value 0
set column active_member to 1 when you send mail to that staff member.
when no member have active_member value column value 0 than Reset all value to 0.

Use PHP sessions to store a server variable, for example: next_email_recip. At the top of your PHP file, you will need to put:
session_start();
if (isset($_SESSION['next_email_recip'])) {
$next_email_recip = $_SESSION['next_email_recip'];
if ($next_email_recip == 3) {
$_SESSION['next_email_recip'] = 1;
}else{
$_SESSION['next_email_recip'] = $next_email_recip + 1;
}
}else{
$next_email_recip = 1;
$_SESSION['next_email_recip'] = 2;
}
In your PHP code, have a simple array:
$arrRecips = array(
"1" => "bob#email.com",
"2" => "joe#email.com",
"3" => "fred#email.com",
);
$this_time_recip = $arrRecips[$next_email_recip];

The best solution is store the email addresses to be used in a table (email_address_table), and each submission in a seperate table (sent_table) then everytime a visitor hits submit, before it saves and gets sent (sent_table), it checks what was the last email address that was used in (sent_table), and check which one is next in the list in the (email_address_table), saves and sent it, that way you can be sure to get an even distribution. And one step further you can add a field (off) in the (email_address_table), that way if somebody is to not use this email address again or it is dedicated and this person is off, you set the status to off, and the rotation will only happen between the remaining agent.

Yes, you can create a table and name it sent_emails. When the first email is sent enter first email address in this table. Then when second user comes and email is sent to him first check this table and if the last two records are of different email ids send to this email address. Do this for all new users like this, means before sending any mail first check their entry in this table for last two records. By creating new table you will also be able to record the time at which emails were sent.

Related

email and password remember me for login after user logged in for the first time

when the user login to his account and click remember me how to make the login form auto-fill the user email and password when the user come to login again so he doesn't have to fill his email and password again in react and next
First of all, store user's credentials on front side (localStorage, lessionStorage and etc.) is not a good practice.
Usually "Remember me" checkboxes are used to create an auth-cookie with longer time life.
For example:
When user checked "Remember me", you will send post request with query params remember=1, server handle this, and send response with header:
Set-Cookie: {auth-cookie}={value}; Max-Age={one week, for example}
It will create a cookie in browser, which time life is one week.
In another case, if user didn't check "remember me", server responds with header like this:
Set-Cookie: {auth-cookie}={value}; Max-Age={one day, for example}
It means that user will be authorized during just one day, after it cookie will be expired, and user will logged out.
User can allow the browser to autocomplete input fields if click "Save password" after submitting the form in browser's popup.
It's browser behavior.
Best regards!
Answer
You can use localStorage, a built-in object in JavaScript for browsers.
localStorage is of type Storage, which means that you can use it via the methods setItem, getItem, and removeItem.
How to use
localStorage.getItem("item1"); // null
localStorage.setItem("item2", "EntityPlantt");
localStorage.getItem("item1"); // still null
localStorage.getItem("item2"); // "EntityPlant"
localStorage.item1; // "EntityPlantt"
location.reload(true); // Reloads page
localStorage is persistent, so you can call it on load to fill in the form.
Examples
onload = () => {
if (localStorage.getItem("data")) {
var data = JSON.parse(localStorage.data);
// fill out the form
}
}
And, when someone fills the form, you can save the form data in localStorage.
btn.onclick = () => {
localStorage.setItem("data", JSON.stringify({
// Form data
}));
submitForm(); // The submitting of the form; your code here
}
Note that localStorage can only store strings. So you can convert them to your type.
var number = parseFloat(localStorage.getItem("number"));
var string = localStorage.getItem("string");
var object = JSON.parse(localStorage.getItem("object"));
var array = localStorage.getItem("array").split(",");
var symbol = Symbol(localStorage.getItem("symbol"));
Reference
If you want to learn more about localStorage (and sessionStorage), go to the MDN docs.
You can use the localstorage of the browser (better encrypted). Then, if the user doesen't refresh the localstorage you will be able to use this information to fill the form.

How to use Google Script to send an email with information collected from Google Form?

For reference: Here is my Google Form.
Here is a Google PE Blank Sheet which has been tied to the output of my Google Form (answers will output on tab Form Responses 2).
I've built up a Google Form capable of collecting a good bit of data. It is meant to be filled out by a manager requesting SAP permissions for a new hire.
They proceed through the Form and enter their primary department (SAP Stream) which leads them to the next page/section that allows the manager to check off what the employee's required permissions will be.
Sometimes, an employee will interface with multiple departments, so the option for a supporting/secondary SAP Stream exists on the second page. This can be continued as needed until all of an employee's requisite roles/permissions are collected in a Google Sheet.
In the Sheet, you will see that:
Columns A-F include basic information
Columns H-T are for the Job Responsibilities
Columns U-AG are a range for the information of one's Supporting SAP Stream
Columns AH-AT are the Supporting SAP Stream's Job Responsibilities
Columns AU-BG collect the Secondary Supporting SAP Stream
I had built Google Script language to collect each of these bits of information in variables which would then get declared as global variables so they could be passed along to an HTML page in the App Script.
Finally, an email consisting of this HTML page would be sent out to the manager in charge of designating SAP permissions.
In previous iterations (which were much simpler), I used an IF statement to check whether a column at the end of the row was empty.
// Loop over the rows
data.forEach((row,i) => {
// Identify whether notification has been sent
if (row[59] === '') {
If it was, the Script would check the Sheet, collecting all of the aforementioned information, and send an email. Then, it would populate that last cell with "Notification Sent" so that the next time the Form was submitted and the Script checked, it would skip sending out a redundant email (and we would have a record that the process went through successfully).
The latest version included variables for
function jobResponsibilities(a){
var z = a.range.getRow();
var valuesA = a.range.getSheet().getRange(z,8,1,13).getValues();
var jobResponsibilities = valuesA.join(' ');
console.log(jobResponsibilities);
}
function supportingSAP(b){
var y = b.range.getRow();
var valuesB = b.range.getSheet().getRange(y,21,1,13).getValues();
var supportingSAP = valuesB.join(' ');
}
function secondaryJob(c){
var x = c.range.getRow();
var valuesC = c.range.getSheet().getRange(x,34,1,13).getValues();
var secondaryJob = valuesC.join(' ');
}
function secondarySAP(d){
var w = d.range.getRow();
var valuesD = d.range.getSheet().getRange(w,47,1,13).getValues();
var secondarySAP = valuesD.join(' ');
}
Collecting the four varying types of information. I used a getRange in order to scope out the exact parts of the Sheet which would have this information and join them together so that the variable could be pulled into the email in a simple table format.
For some reason, upon Form submission, the Notification IF doesn't seem to be running and the email never gets sent.
Is it a problem with the way I've ordered things? Did I improperly build the functions off what you showed me? Is it something as simple as my brackets at the bottom?

How to retrieve a specific data in Firebase Database?

After a user signed in his/her account, he/she will be ask what is his/her user role.
IMG 1: ask user role
After selecting a role, it will then be save in the database,
IMG 2: saved user role
So, how do we retrieve the specific data from Firebase database and then print it in the HTML?
IMG 3: show the user role
These are the codes I used in my .js
function app(user){
function updateMyStatus(e){
var myUpdate={};
myUpdate.email = user.email;
myUpdate.displayName = user.displayName;
myUpdate.status = document.getElementById("clientStatus").value;
fb.child(user.uid).set(myUpdate);
}
function receiveUpdate(received){
var data = received.val();
console.log( data );
document.getElementById('role').innerHTML= "";
}
document.getElementById('userName').innerHTML = user.displayName;
var fb = firebase.database().ref('Accounts');
document.getElementById("clientStatus")
.addEventListener("input",updateMyStatus);
}
and if the user has already a user role(status) as shown in the image 2, how do you hide the Dropbox that is shown in the image 1?
The below will get back your data from Firebase for that account. Then it is a matter of setting the values to their respective HTML elements.
fb.child(AccountId).on(‘value’, callbackFunction)
For reference: https://firebase.google.com/docs/database/web/read-and-write
function receiveUpdate(received){
var data = received.val();
console.log( data );
document.getElementById('role').innerHTML= "";
//hide the dropdown box
document.getElementById("clientStatus").style.display = "none";
}
document.getElementById("clientStatus").addEventListener("input",updateMyStatus);
//put this under your other event listener
fb.child('Accounts').on(‘value’, receiveUpdate);
This code will not work as written. I hope this helps give you a good idea.
Based on your current code, and based on my own understanding of the Firebase Realtime Database, these are the steps you need to take:
Register a listener to listen for changes to the database
To be more specific, you need to add a listener to the particular field that you are interested in in the database.
This listener should preferably not be inside any function.
This listener would check whether a role exists for your user in the database.
If yes, hide the input field and display user's details.
Else, display both the input field and the user's details.
As I have no experience using the Realtime Database (I have only used Cloud Firestore before), I am not very familiar with its syntax. But the link suggested by #Andre Kool and #thezachcannon in the previous post has examples of adding a listener to a particular database reference.
Hope that helped.

How can i show notification per user with jquery and php?

I want show notification per user via API
for example if call api.php?user=1 via server or any admins, show alert to user1 if has any page, for example run alert('hi user 1');
or call api.php?user=2 via server or any admins, show alert to user2, for example run alert('hi user 2');
my solution is :
setInterval(function(){
$.get('ajax_responder.php',dataObj,function(){
});
},5000);
and in api.php saved request and in ajax_responder.php selected notification per user
but this solution not good,and reloaded per 5 second, i want better solution, when called api.php send request to user X
any have solution?!
There's no way the user can receive your notification if the user is not querying the server repeatedly. You can use a websocket to send/receive bi-directional
You can do that.
Step 1) When admin user type message store it in database. you can refer below as example.
TABLE NAME = USER_NOTIFICATION
==================================
USER_ID | IS_READ | MESSAGE
==================================
1 0 Hello User 1
-----------------------------------
2 0 Hello User 2
-----------------------------------
Step 2) Now from front side write Ajax call to keep checking on every minute or 5 minutes interval (Interval depends on server capability to handle the requests), whether for particular login user is having any unread message.
If you are using MySQL then you can use this below query to check unread notifications
SELECT `message` from USER_NOTIFICATION WHERE `user_id` = 1 and `is_read` = 0
now after getting result from above query show it in notification div (Remember create notification div with fixed position so it always popup)
Step 3) when user read admin message that time set is_read flag to 1, so next time that same message will not appear to user
Hope it will help you :)

Multi-Page Order Form with sessions

For my web dev class we have to create a login page, verify it against encrypted records (Id, password) that we have to enter, then step through an order form (while being able to step forward and backward throughout).. so sessions and all that.. I have no idea where to even start aside from coding the html which I've already done.. Any pushes in the right direction would be helpful.. my instructor is abrasive and refuses to help most people without degrading them first.
This is kinda like a longer question.
First at login form you need to check with MYSQL / SQL / DB / etc if the username and password matches.
It's basically like this:
SELECT * from users WHERE username = 'username' AND pass = 'sha1(password)'
Or use the encryption method which you use (md5,sha1,any other for password)
Then you check out if it's returning a row. IF it's return 1 row,then everything is correct.
Then you put all this data to session. I don't know how much you need,but you can put the whole sql result to data. IT doesn't matter here as you said it's a dev class work.
So basically at every of your php you have to start with
session_start();
Then when you verified the user you put the sql result into SESSION like this:
$_SESSION['userdata'] = $sql_row_array;
With this data you can read the current loggedin user's informations. So it's like:
Get username: $_SESSION['userdata']['username']
So you can use this to identify whom bought / ordered the products and insert it into the database.

Categories