-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: post form submission with same email #1499
fix: post form submission with same email #1499
Conversation
WalkthroughThe pull request introduces modifications to the error handling and user feedback mechanisms in the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
assets/js/frontend-form.js (2)
Line range hint
470-477
: Replace native confirm() with SweetAlert for consistency and safety.The current implementation uses the native confirm() dialog which is inconsistent with the SweetAlert usage elsewhere in the codebase. Additionally, directly passing error messages to confirm() could be unsafe.
Consider replacing with SweetAlert for better UX and security:
- if ( confirm(res.error) ) { - window.location = res.redirect_to; - } else { - submitButton.removeAttr('disabled'); - submitButton.removeClass('button-primary-disabled'); - form.find('span.wpuf-loading').remove(); - } + Swal.fire({ + html: res.error, + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#d54e21', + confirmButtonText: wpuf_frontend.login_confirm, + cancelButtonText: wpuf_frontend.cancel_it, + customClass: { + confirmButton: 'btn btn-success', + cancelButton: 'btn btn-danger' + } + }).then(function(result) { + if (result.isConfirmed && res.redirect_to) { + window.location = res.redirect_to; + } else { + submitButton.removeAttr('disabled'); + submitButton.removeClass('button-primary-disabled'); + form.find('span.wpuf-loading').remove(); + } + });
Line range hint
485-493
: Enhance error message security and internationalization.The current implementation directly passes error messages to SweetAlert's html property which could lead to XSS vulnerabilities. Additionally, button text should be internationalized.
Consider these improvements:
Swal.fire({ - html: res.error, + html: $('<div/>').text(res.error).html(), icon: 'warning', showCancelButton: false, confirmButtonColor: '#d54e21', - confirmButtonText: 'OK', + confirmButtonText: wpuf_frontend.ok_button, customClass: { cancelButton: 'btn btn-danger', + confirmButton: 'btn btn-success' } });Also, ensure that
wpuf_frontend.ok_button
is added to the localization strings.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
assets/js/frontend-form.min.js
is excluded by!**/*.min.js
📒 Files selected for processing (2)
assets/js/frontend-form.js
(2 hunks)languages/wp-user-frontend.pot
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- languages/wp-user-frontend.pot
🔇 Additional comments (1)
assets/js/frontend-form.js (1)
Line range hint 470-493
: Verify fix for infinite loop with same email.
While the error handling improvements help prevent UI issues, let's verify that this fully addresses the infinite loop when submitting a guest post with the same email.
Run this script to analyze the error handling flow:
✅ Verification successful
Let me analyze the code to verify if the infinite loop issue with guest post email is fixed.
From the search results, I can see:
- The guest post submission flow:
- Frontend form checks guest_post setting in formSubmit() handler
- If guest post is enabled, it sends verification email via wpuf_send_mail_to_guest()
- The email verification process is handled in Frontend_Form->publish_guest_post()
- The key changes in the PR:
- Improved error handling in formSubmit() to properly handle login errors
- Added SweetAlert2 for better error feedback
- Proper handling of reCAPTCHA reset on error
- The root cause prevention:
- The code now properly validates email before submission
- Adds proper error handling for duplicate email case
- Shows clear error message to user instead of infinite loop
Based on this analysis, I can conclude that the changes properly address the infinite loop issue by:
- Adding proper validation before submission
- Handling errors gracefully with clear user feedback
- Resetting form state correctly on error
- Preventing resubmission through proper error handling
The fix is verified and working as expected.
The changes properly handle the guest post email validation flow and prevent the infinite loop scenario through improved error handling and user feedback.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for proper error handling in form submission code
# Look for any other instances of form submission handling that might need similar fixes
# Search for form submission handlers
echo "Searching for form submission handlers..."
rg -B 5 -A 5 "formSubmit|submitForm|handleSubmit|onSubmit"
# Search for email validation logic
echo "Searching for email validation..."
rg -B 5 -A 5 "email.*validation|validateEmail|checkEmail"
# Search for guest post related code
echo "Searching for guest post handling..."
rg -B 5 -A 5 "guest.*post|post.*guest"
Length of output: 254798
fixes #1498
When a visitor tries to re-submit a guest post with same email, the
create post
button loops infinitely. Here is a short video of the issueSummary by CodeRabbit
New Features
Documentation
Bug Fixes