I have been fiddling with this for a while, so going to post this question.
I have the Login Tools Signup object I converted to a form.
Added in my own custom fields and inputs.
ie: Address, City, Province, PostalCode, MobilePhone and HomePhone
Modified the code as outlined in your help and this is working 100%
I have two questions . . .
1. During the Submit process if an error is found with code like . . .
if ($newpassword != $confirmpassword)
{
$error_message = 'Password and Confirm Password are not the same!';
}
All user inputs in all textboxes are cleared out.
QUESTIONS.
1. What code do I need to add to retain the user inputs on the form with a submit error_message involved?
2. How do I set the focus back to the input that raised the error_message?
Like I know how to do this with Java and returning false to flag the submit failure.
I don't see how to do this with the existing code in the HTML Signup block of code?
Any help would be appreciated!
Pete,
Error_Message after Submit Clears Inputs
Forum rules
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/login_basics.html
http://www.wysiwygwebbuilder.com/login_tools.html
TIP:
A lot of information about the login tools can be found in the help/manual.
Also checkout the demo template that is include with the software.
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/login_basics.html
http://www.wysiwygwebbuilder.com/login_tools.html
TIP:
A lot of information about the login tools can be found in the help/manual.
Also checkout the demo template that is include with the software.
Error_Message after Submit Clears Inputs
Last edited by peters on Sat Oct 14, 2023 11:20 pm, edited 1 time in total.
Re: Error_Message after Submit Clears Inputs
I'm sorry, but I cannot help you with coding related issue. This is beyond the scope of the support I can give you.
Re: Error_Message after Submit Clears Inputs
I have not tried this, but in the "Validate" tab of the $confirmpassword field, if you switch to Bootstrap as the validation method, you can select the "Match" option and specify the field for $newpassword as the matching criteria. I'm not sure if this validation occurs before the form is cleared or not, so you would have to test. I also suspect you would need to use Bootstrap on all fields for validation, just for consistency's sake.
Billing clients for your freelance work? Try Minute-2-Minute, the project management, timing, and billing system. Perfect for web developers who charge by the hour. FREE 45-day trial.
Re: Error_Message after Submit Clears Inputs
Good day to everyone!
This thread is about a Signup form object in the ToolBox that was converted to a form.
In follow up to the original post, I asked; "How to maintain user inputs on a form when error messages fire in association with the submit process?"
We all know the behavior when the submit happens and that is the user's inputs are cleared by default on the form.
This is a very annoying behavior. If the user had 10-15 entries he/she inputted and then forgot say the @ sign in their email address entry, when they Submit the form the error message fires and all their accurate entries such as : Full name, User ID, User Password, Confirmed Password, Address, City, etc.; all vanish.
Man I have run into this myself on website and mumble a few choice words when this happens! lol
So my aim was to try and find a work-a-round solution within WWB without drastically rewriting the entire php code in the Signup HTML file associated with the form. Realizing some customization maybe required, but try to keep the changes to the minimum.
I think I found a WWB work-a-round to this that does what I was after and not loose all the user's data entries on the form.
Here is how I handled in within WWB with some minor modification to the code . . .
- Created a error page that will be called when an input error is sensed.
- If you look at the top of the php code for the form I have a error page assigned.
$error_page = './cus-AccntFailedEmail.php';
- Take the error code string and pass it into this error page so a textbox in this error page denotes the error encountered. I used the PHP session to perform this task.
Page 1 - The Signup page . . .
<?php
session_start();
// Later in the page where the actual error trapping if conditions are found.
$error_message = 'Fullname is not valid, please check and try again!';
// Catch the error message and save it into a session memvar.
$_SESSION['errmsg'] = $error_message;
?>
Page 2 - The error display page . . .
<?php
session_start();
$errormessage = '';
$errormessage = $_SESSION['errmsg'];
?>
In the body a textbox set as disabled with the following value . . .
<?php echo $errormessage; ?>
Just remember the sesssion_start() call needs to be the first line of code in both webpage files.
- As each test is done in the php code, call the error page when the error is encountered.
As an example . . .
if (!preg_match("/^[A-Za-z0-9-_!.@$ ]{1,50}$/", $newfullname))
{
$error_message = 'Full name is required!';
// Below is where I add one line of custom code to store the error message.
$_SESSION['errmsg'] = $error_message;
header('Location: '.$error_page);
}
You see above when there is an issue with the fullname my custom error page is called using: header('Location: '.$error_page);
- OK, now to the error page itself . . .
- Textbox to display $error_message that in this case is: "Full name is required!"
- One button to Cancel completely creating a new account with a link taking you back to say the main Index page.
- A second button that says "Try Again?"
- In the Try Again button go to the Events tab and add a new event.
- Set this new event to fire with the onclick event.
- Set the event action to Javascript.
- Set the JavaScript to file as: history.back();
I think by now you see what is going to happen.
The input error is displayed and the fact it is on it's own form you can be specific in the error as you have much more room than the 30-35 characters in the error_message back in the stock Signup form. ie: Email address @ sign is missing, etc.
You select the try Again button and the Javascript history.back() call returns you to your input form and the values that were entered in previously by the user remain.
This is probably the work-a-round I am going to use. I end up with a really good way to add more details to the actual entry error and at the same time I can Try Again and no previously inputted data is lost.
This was one of the ways I tried, but with this one I am not making major changes to the php script and only add in the one line to call the error form at each If condition where I validate user inputs.
Pete,
This thread is about a Signup form object in the ToolBox that was converted to a form.
In follow up to the original post, I asked; "How to maintain user inputs on a form when error messages fire in association with the submit process?"
We all know the behavior when the submit happens and that is the user's inputs are cleared by default on the form.
This is a very annoying behavior. If the user had 10-15 entries he/she inputted and then forgot say the @ sign in their email address entry, when they Submit the form the error message fires and all their accurate entries such as : Full name, User ID, User Password, Confirmed Password, Address, City, etc.; all vanish.
Man I have run into this myself on website and mumble a few choice words when this happens! lol
So my aim was to try and find a work-a-round solution within WWB without drastically rewriting the entire php code in the Signup HTML file associated with the form. Realizing some customization maybe required, but try to keep the changes to the minimum.
I think I found a WWB work-a-round to this that does what I was after and not loose all the user's data entries on the form.
Here is how I handled in within WWB with some minor modification to the code . . .
- Created a error page that will be called when an input error is sensed.
- If you look at the top of the php code for the form I have a error page assigned.
$error_page = './cus-AccntFailedEmail.php';
- Take the error code string and pass it into this error page so a textbox in this error page denotes the error encountered. I used the PHP session to perform this task.
Page 1 - The Signup page . . .
<?php
session_start();
// Later in the page where the actual error trapping if conditions are found.
$error_message = 'Fullname is not valid, please check and try again!';
// Catch the error message and save it into a session memvar.
$_SESSION['errmsg'] = $error_message;
?>
Page 2 - The error display page . . .
<?php
session_start();
$errormessage = '';
$errormessage = $_SESSION['errmsg'];
?>
In the body a textbox set as disabled with the following value . . .
<?php echo $errormessage; ?>
Just remember the sesssion_start() call needs to be the first line of code in both webpage files.
- As each test is done in the php code, call the error page when the error is encountered.
As an example . . .
if (!preg_match("/^[A-Za-z0-9-_!.@$ ]{1,50}$/", $newfullname))
{
$error_message = 'Full name is required!';
// Below is where I add one line of custom code to store the error message.
$_SESSION['errmsg'] = $error_message;
header('Location: '.$error_page);
}
You see above when there is an issue with the fullname my custom error page is called using: header('Location: '.$error_page);
- OK, now to the error page itself . . .
- Textbox to display $error_message that in this case is: "Full name is required!"
- One button to Cancel completely creating a new account with a link taking you back to say the main Index page.
- A second button that says "Try Again?"
- In the Try Again button go to the Events tab and add a new event.
- Set this new event to fire with the onclick event.
- Set the event action to Javascript.
- Set the JavaScript to file as: history.back();
I think by now you see what is going to happen.
The input error is displayed and the fact it is on it's own form you can be specific in the error as you have much more room than the 30-35 characters in the error_message back in the stock Signup form. ie: Email address @ sign is missing, etc.
You select the try Again button and the Javascript history.back() call returns you to your input form and the values that were entered in previously by the user remain.
This is probably the work-a-round I am going to use. I end up with a really good way to add more details to the actual entry error and at the same time I can Try Again and no previously inputted data is lost.
This was one of the ways I tried, but with this one I am not making major changes to the php script and only add in the one line to call the error form at each If condition where I validate user inputs.
Pete,
-
-
- Posts: 9
- Joined: Tue Nov 14, 2023 8:27 am
Re: Error_Message after Submit Clears Inputs
Hi all,
chatgpt said:
The HTML form fields are being emptied because the form is being submitted to the same page (action="<?php echo basename(__FILE__); ?>"). When the form is submitted, the page reloads, and the PHP code at the beginning of the file is executed. This code initializes variables like $newusername, $newemail, etc., to empty values each time the page is loaded.
To retain the user input in the form fields when there is an error, you need to modify the code to repopulate the form fields with the values submitted by the user. Here is the modification you can make:
php
Copy code
<tr>
<td class="row"><input class="input" name="fullname" type="text" id="fullname" value="<?php echo htmlspecialchars($newfullname); ?>"></td>
</tr>
<!-- Repeat this for each input field, replacing the value attribute accordingly -->
You need to add value="<?php echo htmlspecialchars($variable); ?>" to each input field in your form to display the previously entered values. Make sure to replace $variable with the corresponding variable for each input field.
Here's an example for the first two fields:
php
Copy code
<tr>
<td class="row"><input class="input" name="fullname" type="text" id="fullname" value="<?php echo htmlspecialchars($newfullname); ?>"></td>
</tr>
<tr>
<td class="row"><input class="input" name="username" type="text" id="username" value="<?php echo htmlspecialchars($newusername); ?>"></td>
</tr>
Repeat this pattern for each input field in your form. This will display the previously entered values if there is an error during form submission.
I gave chatgpt my original code and after 6 tries it gave me the correct code that works.
cheers
Egon
chatgpt said:
The HTML form fields are being emptied because the form is being submitted to the same page (action="<?php echo basename(__FILE__); ?>"). When the form is submitted, the page reloads, and the PHP code at the beginning of the file is executed. This code initializes variables like $newusername, $newemail, etc., to empty values each time the page is loaded.
To retain the user input in the form fields when there is an error, you need to modify the code to repopulate the form fields with the values submitted by the user. Here is the modification you can make:
php
Copy code
<tr>
<td class="row"><input class="input" name="fullname" type="text" id="fullname" value="<?php echo htmlspecialchars($newfullname); ?>"></td>
</tr>
<!-- Repeat this for each input field, replacing the value attribute accordingly -->
You need to add value="<?php echo htmlspecialchars($variable); ?>" to each input field in your form to display the previously entered values. Make sure to replace $variable with the corresponding variable for each input field.
Here's an example for the first two fields:
php
Copy code
<tr>
<td class="row"><input class="input" name="fullname" type="text" id="fullname" value="<?php echo htmlspecialchars($newfullname); ?>"></td>
</tr>
<tr>
<td class="row"><input class="input" name="username" type="text" id="username" value="<?php echo htmlspecialchars($newusername); ?>"></td>
</tr>
Repeat this pattern for each input field in your form. This will display the previously entered values if there is an error during form submission.
I gave chatgpt my original code and after 6 tries it gave me the correct code that works.
cheers
Egon