Skip Navigation

[Resolved] CRED User Form remove required email field

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to remove the required email field from a new User Form.

Solution: Use expert mode in the Form editor to delete the shortcodes responsible for displaying the email field.

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by yonatanc 3 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1864623

Tell us what you are trying to do?
register new user with cred user form, without an email field

i can disable the email field requirement for the generic wp register forms, with this code:

// disable empty email errors on "user_profile_update_errors"

add_action('user_profile_update_errors', 'my_user_profile_update_errors', 10, 3);
function my_user_profile_update_errors($errors, $update, $user) {
$errors->remove('empty_email');
}

// on 'user_new_form', 'show_user_profile', 'edit_user_profile' cancel required email with jquery

add_action('user_new_form', 'my_user_new_form', 10, 1);
add_action('show_user_profile', 'my_user_new_form', 10, 1);
add_action('edit_user_profile', 'my_user_new_form', 10, 1);

function my_user_new_form($form_type) {
?>
<script type="text/javascript">
jQuery('#email').closest('tr').removeClass('form-required').find('.description').remove();

<?php if (isset($form_type) && $form_type === 'add-new-user') : ?>
jQuery ('#send_user_notification') .removeAttr('checked');
<?php endif; ?>
</script>
<?php
}

i am not using it at the moment,

can this code help me removing the required email field on a user cred form?

the generic wp hook for 'user_new_form' (in the add_action used above) aplay to the new user cred form as well?

is there a hook for the new user cred form that can be used just as the generic one 'user_new_form'?
or what do you suggest for me to create a new user form without email or a hidden hack?

What is the link to your site?
changba.binet.co.il

#1864715

i know i can use the cred forms api hooks, like -

- filter the email field with some code
cred_filter_field_before_add_to_form

- if needed make sure to cancel the email validation if present in:
cred_form_validate

- if needed some actions before saving
cred_before_save_data
- or during saving
cred_save_data

or it is not needed to actually ?

#1865003

Hello, if you want to remove the email field from a User Form, you can do that manually by switching to Expert Mode in the Form editor panel. Then you can delete the shortcodes responsible for displaying the email field and its related HTML markup. It's probably easier this way than adding various PHP filters and custom validation code. Once you remove the email field in the Expert Form editor, there is no need for additional validation code. The new User will be created without an email address, and no field errors will be triggered in the Form.

#1865063

1. how can i create the password in a hidden way (and secure)?

here is my case:

i have an ajax form with phone input, the action sends sms with 4dig code (my custom php code, working great)

the 4dig "code" generated by my ajax action (in a functions.php function) is prefixed with the phone number and this is the needed password

$pass = $mobile .  $rand_num

i need to pass this data to the new user cred form (presumably with js)

2. how can i utilize the conditional output - to output a new user cred form or a login - when:
i'll have the username (phone number, maybe pass it through url param) to check if its exist, if not then show new user form (and populate a the hidden username field to have value from url param? )

#1865085

Okay if you're able to remove the email field as described, we can continue addressing your new questions in separate tickets as needed.

i need to pass this data to the form (presumably with js)
There is no public JavaScript API available for Forms, so you would need to do this with your own custom JavaScript in an AJAX callback. In general, you can set the value of any input field using jQuery, like so:

var valueToSet = 'abc12345';
jQuery('input[name="some-input-field-name"]').val(valueToSet);

You can inspect the Form's input fields on the front-end of the site to determine which unique attribute selector is most useful in your Form. More info about jQuery's APIs available here:
https://api.jquery.com/category/selectors/attribute-selectors/
https://api.jquery.com/val/
Since there is no public Forms JavaScript API, extensive support for this type of functionality is not offered here in the forums per our support policy: https://toolset.com/toolset-support-policy

2. how can i utilize the conditional output - to output a new user form or a login - when: i'll have the username (phone number, maybe pass it through url param) to check if its exist, if not then show new user form
A conditional that shows a Form or shows some other content should be implemented outside the Form, either in the Page or post that contains the Form, or in a Content Template applied to that Page or post. This sounds like a separate issue from disabling an email field inside the Form. In another ticket, our support team can give you more information about using a Conditional Block or a conditional shortcode to test the value of a URL parameter. I can split off a separate ticket if you need more assistance with this, just let me know.

(and populate a the hidden username field to have value from url param? )
You can use a URL parameter to set the value of any field in a Form. In the drag-and-drop Form builder, you can open each field's settings to set a URL parameter. In the Form builder's expert mode, you can use shortcode attributes to define which URL parameter should be used as the field value. See the documentation for each Form field shortcode available here, with information about URL parameters: https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/
Again, if you need more information about this let me know and I can split off a new ticket for you where we can discuss in more detail.

#1865449

My issue is resolved now. Thank you!