Check if input field is empty or not - codeigniter

I have 10 textboxes x 3 so about 30.
Name - Age - SEx
so 10 persons in all.
I have this current code:
if(array_key_exists('submit',$_POST)){ //CHECKS IF FORM WAS SUBMITTED, ELSE LOADS TO VIEW
for($counter=1;$counter<11;$counter++){ //I LOOPED THE 10 FIELDS, STARTING FROM 1, 1-10
if($_POST['ingredient'.$counter]!=null){ // CHECK IF ATLEAST NAME IS NOT EMPTY, IF EMPTY EVEN IF THE OTHER 2 INPUTS ARE NOT I WILL NOT INCLUDE IT.
$this->form_validation->set_rules('Name'.$counter,'Name #'.$counter,'trim');
$this->form_validation->set_rules('Age'.$counter,'Age of'.$_POST['name'.$counter],'trim|required|numeric');
$this->form_validation->set_rules('Sex'.$counter,'Gender of'.$_POST['name'.$counter],'trim|required');
}
Im only adding required on the other 2 fields since name shouldnt be null to be inside the if(success){ } clause
Is there any other better way?
CALLBACK QUESTIONS.
When using form_validation, say i used a callback function. how would i be able to print the necessary error_message for that callback since ci wont be able to know what that function was all about.

Related

How to write a Go/Gin general function of 14 behaviors, and then call or check it in a certain place?

There are nearly 14 behaviors of sending points to users, such as user registration, login, purchase, and chat. It is required not to change the previous interface code in Go.
id
motion
points
remark
1
/register
5
one user only have one chance to get points
2
/login
5
every day the user has one chance to get points
3
/comment
3
every day the user has five chance to get points
4
/pay
10
every day the user has three chance to get points
5
/invite
10
every day the user has three chance to get points
6
/send
10
every day the user has three chance to get points
7
/purchase
10
every day the user has three chance to get points
Every day the user only has 100 points
Through the following partial code of /register every user can get 5 points after he registers successfully.
func (r *User) CreateUser(CreateUser *CreateUserModel, c *lmhttp.Context) {
err = r.userDB.insertScoreTx(CreateUser.UserID, 1, 5)
if err != nil {
r.Error("Send points failed", zap.Error(err))
c.ResponseError(errors.New("Send points failed"))
return
}
c.Response(LoginUserDetail(UserModel, token, r.ctx))
}
And the data of table user_points is as below:
id
user_id
points
points_type
1
1
5
1
Can I write a general function of sending points, and then call or check it in a certain place, that is, judge whether to increase points when each interface request is successful, such as the following places where each interface responds successfully?
// Response OK
func (c *Context) ResponseOK() {
c.JSON(http.StatusOK, gin.H{
"status": http.StatusOK,
})
}
Thanks so much for any advice
You can definitely do what you're asking. I don't know Go but some webservers will have a hook to run a function on every successful request. In that function based on the URL you can check if to add points for the user. You are already storing the type of points but you also need to store how many chances they used up for the day.
Then you can write the logic for whether they add points for each of the rules.
If in Go there is no hook function that runs on any request you can go as basic as a function that takes in e.g 'register', 'login'. And call it manually from everywhere you handle the requests you wanna add points for.
You also need to reset the data based on the date since all the rules are "today".
My best advice for that is to also store the current date on all the user_points entries. And when checking whether to add points if the current day is not today you set the number of used up chances to 1 and the date to current.
e.g table
id
user_id
points
points_type
chances_used
date
1
1
5
1
2
14:33 09/02/2023
e.g logic from inside the function:
if type == 'comment':
points = db.get(user_points).filter(user.id=1, points_type=3)
if points.date == date.today():
points.chances_used += 1
if points.chances_used < 5
user.points += 3
if points.date < date.today():
points.chances_used = 1
points.date = date.now()
user.points += 3
Though thinking about it now this means you would lose record of where a users points came from because I am using user.points to store the actual value.
You might wanna just add a row to the table every-time you check instead. And get the data instead of something like db.get(user_points).filter(user.id=1, points_type=3), just get the users latest for that point_type. And use that row to check the date and get the chances_used but save your data into a new row.
You could create a dedicated struct or function to handle scores. From what I see in the code in order to apply points to the user you would need to pass a few information such as userDB, UserId, points_type and points, the same what you already have in the code. If you want the function to be stateless and available everywhere you can define it in dedicated userpoints package and simply export:
func SendPointsTo(db userDB, userId, pointsType, pointsCount int) error {
err := d.insertScoreTx(userId, pointsType, pointsCount )
if err != nil {
return errors.New("Sending points failed")
}
return nil
}
Don't mix logic of creating user with some other actions - it introduces confusion and breaks SRP. It's better to make a dedicated createUserHandler which performs chains of steps defined by the contract. A part of the contract would then be additional SendPointsTo func call.
Is it what you mean? If not can you be more preciseful in problem definition?

Validation list with multiple criterias

I sort out my problem but I am wondering if an easier way doing it doesn't exist.
With the function onEdit(), I am creating from a first validation list, a second validation list in the next cell.
So, the code below is just for information.
var validationRange = data.getRange(3, myIndex, data.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
In this validation list, I need to select a name, taking into account two additionnal criterias :
Name
Times
LastWeek
Patrick
2
W22
Rachel
5
W15
Claire
3
W14
Olivier
4
W16
Hélene
2
W20
It means that "Patrick" attended "2" times and last time was in week "W22".
I need to take into account these two criterias to select one of the attendee
I.E. : I try to let each person participate the same number of times but not every week (the oldest first)
So, I created a validation list with a "sorted key" that allows me to first see the person who has attended less and for longer.
Key Sorted
#02W20#Hélene
#02W22#Patrick
#03W14#Claire
#04W16#Olivier
#05W15#Rachel
This validation list is used 3, 5, 7 times in the same sheet because person can do different activities. Then, when all person are selected another script removes the values between # to keep only the name in the final sheet.
So, the question is :
could we create a validation list with multiple columns, the selected value being only the value of the first column.
I guess many users would enjoy it when we glance at questions about multiple criteras selection lists.
Thanks

Oracle Apex Add IF Statement to set a value in a form

I am working on a system in Oracle Apex 22.1 where there is a Form, where the user enters an amount of money to be validated by the company. There are 3 fields which are a select list P3_REQUEST_TYPE, a text field P3_AMOUNT and a select list P3_TYPE_CURRENCY. What I want to do is that if the user selects the option "Payment Request" in P3_REQUEST_TYPE, and according to the amount entered in P3_AMOUNT and the type of currency in P3_TYPE_CURRENCY (USD, JPY), put the value "1" in the field P3_FG_RT for validation reasons.
I would like to know if there is a way to do it through a IF function since through dynamic actions I have not been able to make it work, I would greatly appreciate your help.
The amounts for the "1" to be placed are: if it is greater than or equal to 5,000 and they are USD, or if it is greater than or equal to 18,000 and they are JPY.
That looks like dynamic action, indeed.
its action would be "Set value"
type might be PL/SQL Function body:
RETURN CASE WHEN :P3_REQUEST_TYPE = 'Payment Request'
AND :P3_TYPE_CURRENCY IN ('USD', 'JPY')
THEN 1
END;
items to submit: P3_REQUEST_TYPE, P3_TYPE_CURRENCY
affected elements: item, P3_FG_RT
Though, as you said that these are Select List items, I kind of doubt that return values really are "Payment Request" or "JPY" - I presume that you actually return their codes, not descriptions so CASE expression might need to be changed.
The decision to use a dynamic action depends on the following question: is the value that needs to be set of importance before the page is submitted or does it only matter at submit time
#Littefoot explained how to do the dynamic action but if this value is only needed after the page is submitted, it is easier to set the value of page item P3_FG_RT with a a computation (process point After Submit).
One way to implement this computation is:
Type: Static Value
Static Value: 1
Server Side Condition: Expression
PL/SQL Expression:
:P3_REQUEST_TYPE = 'Payment Request' AND :P3_TYPE_CURRENCY IN ('USD', 'JPY')

Acrobat XI - Blanking a field if conditions are met

I have a form my drivers complete where part of the form is related to fueling. There is a possibility of 6 separate fuel stops. Each fuel stop line has input where gallons and cost are also included. By default the Cost and Gallons purchased cost is set to $0.00.
My reason for asking assistance:
Occasionally the drivers will inadvertently clicks into one of the date fields on a fueling line and the date will auto populate with the then current date (which can be changed). Then the rest of that line remains all zeros.
I am trying to figure out a validation script that will put the date field back to NULL preferably (or blank) if the Fuel Purchase Cost is at $0.00 as well as the DEF Purchase Cost is also $0.00. BOTH of these items need to be true. Additionally I am not sure how to keep the user inputted DATE if FUEL_PURCH_STOP_1 is >0 AND DEF_PURCH_STOP_1 >0.
NOTE: Fueling will always span 2-3 days.
My end goal is... If a driver clicks in the date field inadvertently, the current date is auto populated. Then if there is a "0" in the both the FUEL_PURCH_STOP_1 AND DEF_PURCH_STOP_1 fields then remove the date from that line. If either one or both of the two fields have a value >0 then I want to keep the user inputted date in the field.
I tried:
var v1 = +getField("FUEL_PURCH_STOP_1").value;
var v2 = +getField("DEF_PURCH_STOP_1").value;
// Set this field's value
if v1 >0 andalso v2 >0) {
event.valueAsString === "WHAT GOES HERE??";
} else {
event.valueAsString === "";
}
Put the following script into the custom calculation for your date field.
var v1 = this.getField("FUEL_PURCH_STOP_1").value;
var v2 = this.getField("DEF_PURCH_STOP_1").value;
// Set this field's value
if (v1 == 0 && v2 == 0) {
event.target.value = "";
}
Using this script, the date entry will only get modified if both of the other fields are zero. It's left as is when the criteria is not met so you don't actually need the "WHAT GOES HERE??" value.

Errors when grouping by list in Power Query

I have a set of unique items (Index) to each of which are associated various elements of another set of items (in this case, dates).
In real life, if a date is associated with an index, an item associated with that index appeared in a file generated on that date. For combination of dates that actually occurs, I want to know which accounts were present.
let
Source = Table.FromRecords({
[Idx = 0, Dates = {#date(2016,1,1), #date(2016,1,2), #date(2016,1,3)}],
[Idx = 1, Dates = {#date(2016,2,1), #date(2016,2,2), #date(2016,2,3)}],
[Idx = 2, Dates = {#date(2016,1,1), #date(2016,1,2), #date(2016,1,3)}]},
type table [Idx = number, Dates = {date}]),
// Group by
Grouped = Table.Group(Source, {"Dates"}, {{"Idx", each List.Combine({[Idx]}), type {number}}}),
// Clicking on the item in the top left corner generates this code:
Navigation = Grouped{[Dates={...}]}[Dates],
// Which returns this error: "Expression.Error: Value was not specified"
// My own code to reference the same value returns {0,2} as expected.
CorrectValue = Grouped{0}[Idx],
// If I re-make the table as below the above error does not occur.
ReMakeTable = Table.FromColumns(Table.ToColumns(Grouped), Table.ColumnNames(Grouped))
in ReMakeTable
It seems that I can use the results of this in my later work even without the Re-make (I just can't preview cells correctly), but I'd like to know if what's going on that causes the error and the odd code at the Navigation step, and why it disappears after the ReMakeTable step.
This happens because when you double click an item, the auto-generated code uses value filter instead of row index that you are using to get the single row from the table. And since you have a list as a value, it should be used instead of {...}. Probably UI isn't capable to work with lists in such a situation, and it inserts {...}, and this is indeed an incorrect value.
Thus, this line of code should look like:
Navigate = Grouped{[Dates = {#date(2016,1,1), #date(2016,1,2), #date(2016,1,3)}]}[Idx],
Then it will use value filter.
This is a bug in the UI. The index the UI calculates is incorrect: it should be 0 instead of [Dates={...}]. ... is a placeholder value, and it generates the "Value was not specified" exception if it is not replaced.

Resources