This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

additional registration fields cleared on submit

In Modifications and Hackery · Started by eric on 2019-06-01 12:03 pm · 14440 views · 4 replies

The concept of [size=small]usersc/scripts/additional_join_form_fields.php works great, but I am having trouble with the two parts of validation.[/size]

[size=small]My fields get validated before submit, but on submit the original user form fields get validated, like username and email, and all my additional field inputs are gone if there is an error.[/size]

[size=small]That is, the user fills out the complete registration page, including the standard fields and my additional fields, the validation confirms all my required fields, but on submit they lose their additional field inputs.[/size]

[size=small]I think it's because my fields are validated when the submit button is pressed but prevent the form contents from being posted, but the original user registration form fields are validated only after being posted. At that point, the error messages are displayed at the top, but all my additional form fields are now blank. (I have several fields because they are essentially applying to register).[/size]

[size=small]Is there an additional step I'm missing?[/size]

[size=small]Eric[/size]
Hi Eric. I want to make sure I understand your question. Are you saying that the inputs themselves are gone or the data the people typed in the inputs are gone?

Hi Eric. I want to make sure I understand your question. Are you saying that the inputs themselves are gone or the data the people typed in the inputs are gone?

Good clarification. The input fields are still there, but they are cleared.
Ok. So what you want to do is let's say you have a text field of "address"

You would do

<input type="text" name="address" value="<?php if(!empty($_POST['address'])){echo $_POST['address'];}>

I think that's it. I'm not in my code editor, but the idea is that if a form has been posted, you need to re-echo whatever they put in the form field if it fails validation.

Ok. So what you want to do is let's say you have a text field of "address"

You would do

<input type="text" name="address" value="<?php if(!empty($_POST['address'])){echo $_POST['address'];}>

I think that's it. I'm not in my code editor, but the idea is that if a form has been posted, you need to re-echo whatever they put in the form field if it fails validation.

That makes perfect sense. I wasn't thinking about it already being in the $_POST variable. I tried a couple fields as a test, and it's working perfectly - thank you for the help and the quick response!

I'm happy I made the choice to build on userspice!