saving one object in 2 steps with activerecord - validation

in my user model i have attributes nikname, email, password, and country, about how to register users i want do this in 2 steps :
the first page shows form with 3 fields ( nikname, email, password ) , then user fills them and clicks signup button, and he will be redirected to a second page
the second page shows him a form with the last field ( country ) , then user fills it and clicks finish button to finish his registration
how i can do this ("saving 1 object in 2 step") , and for each step get errors of validation for each form

Maybe this gem https://github.com/schneems/wicked could help you...
Cheers

Related

Laravel 8 - count clicks but user can't spam the function

In my website I track clicks on a specific link and save the count on database with this function:
public function redirect($url)
{
$data = Class::where('url', $url)->first('clicks');
$cnt = $data->clicks;
$cnt++;
$sql = Class::where('url', $url)->update([
'clicks' => $cnt,
]);
if (!$sql) {
abort(500);
}
return redirect('https://website.com/'.$url);
}
the problem is if someone spam the link , the count goes up. I want stop count if user clicked on link 5mins ago.
he will redirected to the link but count doesn't go up.
I'm new so it's so good if you explain it with details. Thanks
I would create a new table, lets call it link_clicks. You will need 3 columns, one to identify the person, one to get the time and one to identify the link (I dont exactly know how you store the links you want to observe).
So more or less you will have the following table:
link_clicks
user_id
link_id
created_at
If the users are always logged in, I would store the user_id, if they are not logged in, I would store the IP-address. So instead of user_id make a column called ip or ip-address.
Afterwards you can easily get the last click and its time.
--Example
Your new table contains following entry:
user_id = 1, link_id = 1 and created_at = 2021-04-21 19:00:00
Now in your controller you get the current date_time date("Y-m-d H:i:s") and the user id like that: auth()->id(). You can also define your time treshold in minutes e.g max_dif = 5.
Afterwards you can query the table for all clicks for the user. You can either make the time comparision in your where() statement or you can make some comaprison in your php code to check if the time treshhold is reached.

i want to show the phonenum of the user if it is already entered then the it will show the phonenum

hi i am trying to show the phone num of the user if it is already entered then the num will show in the input field
<input type="tel" name="phonenum" id="phonenum" #if(isset($user))
{{$user->Phonenum}}
#endif>
i am trying to show it in this manner it is not working any suggestion ??
how can i show the number of the user if it has already been entered by the user .
here in the user table
$table->integer('Phonenum')->nullable();
the field is set in this manner .any suggestion??

Counting a field value response weekly basis in Lotus Notes

I have radio button field in a form whose value can be 1 or 2 or 3. I have a made a view out of this form and there one column will contain the value of this radio button field . Whenever a customer submits the form, a new document will appear in the view. A customer can submit the form many times with different value of this radio button. Is it possible to know how many times a particular customer selected the value 1?
Yes, you can create a view where the first column is your customer name and the second column is their response. Both columns should be "categorized" meaning they'll group the like values.
For each column you can set the formula to include the number of documents within the group. For example:
CustomerName + " (" + #DocChildren + ")"
will show you "ABC Company (12)" if ABC had 12 responses.

Show an image on certain products description only when customer is logged in

I'm having a problem with Magento, how do I show an image on certain products description only when customer is logged in? And is it possible to access to which customer group the customer belongs to after logged in? So that if it's a regular customer he see's some image or not, if is a distributor he sees another kind of image.
I'm talking of images in the product description, has a banner in the beggining of the text, Im not talkign about product images.
You'll need to modify your themes catalog/product/view/description.phtml template as that's where the product description is output.
$customerSession = Mage::getSingleton('customer/session');
$customer = $customerSession->getCustomer();
if ($customerSession->isLoggedIn()) {
// your image actions here
}
if ($customer && $customer->getCustomerGroupId() == 5) {
// your customer group specific actions
}
The first if statement checks if the user is logged in, the second checks if the customer group ID is equal to 5 (or whatever customer group you're searching for.) Place this before your description to output the necessary image / content.

Infopath 2007 - How do I perform data validation on the current view ONLY?

I have an infopath 2007 form that I am developing which uses 3 different views.
The 3 different views are basically the same form, but have different text boxes shown, depending upon what button the user selects.
I run into a problem where 'view 1' has some form validation, but the user has selected 'view 2' and submits it. The form validation on 'view 1' is triggered, and the user cannot submit the form.
How can I ignore the form validation on 'view 1' if the user is currently submitting 'view 2'?
Rather than tick the standard "this field cannot be blank" checkbox (for example), you need to use the Data Validation rules instead. Lets say you have two views with a textbox in each that cannot be blank, but you want to only enforce the current view. Here's the structure of the form:
fields:
currentView (number) (default = 1)
text1 (text)
text2 (text)
button1
button2
view 1 ( default)
text1 - rule: if (currentView = 1 AND text1 is blank) show "cannot be blank"
button1 - action: set a fields value (currentView = 2); switch views (to 2)
view 2:
text2 - rule: if (currentView = 2 AND text2 is blank) show "cannot be blank"
button2 - action: set a fields value (currentView = 1); switch views (to 1)
Make sense?
Oisin

Resources