Skip Navigation

[Resolved] Clear field value upon form submission?

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

Problem: I have a custom field in a Form that allows Users to submit a comment. When the Form is submitted, I would like to save the comment so it can be viewed on the backend of the site. When the Form is loaded again on the front-end, I would like to show the field as empty so the next User can submit their own comment without seeing the previous comment.

Solution: Set the value of the field to be an empty space surrounded by quotation marks:

cred_field field='revision-summary' post='vehicle' value=' ' urlparam='' class='form-control' output='bootstrap']

Update any form validation scripts you have to account for the empty string.

This support ticket is created 5 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.

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 1 reply, has 2 voices.

Last updated by Christian Cox 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#904290
contributors.jpg

Tell us what you are trying to do?
I have a required field that contributors must enter in a value, before being able to submit the form. This information is only so I know as an administrator what they've changed.

Once Ive actioned the submission in the back end, this information is no longer needed. At the moment the information is stored within the database, which means unless I clear it manually, its going to carry that value over so when the next contributor wants to make a change, they'll see the information entered into this field by the previous contributor. its not a big deal, but having to remember to clear it every time I action a submission in the back end is going to eventually become a nuisance.

How can I either reset the value to null when the form itself loads, or clear it upon submission of the form?

Is there any documentation that you are following?
I did find these two threads, but Im not sure if this is what I need?

https://toolset.com/forums/topic/overwrite-value-with-preset-generic-field-value/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Is there a similar example that we can see?
Sure. Code for the CRED form below.

[credform class='cred-form cred-keep-original']

	[cred_field field='form_messages' value='' class='alert alert-warning']

	<div class="form-group">
		<label>Vehicle Description</label>
		[cred_field field='post_content' post='vehicle' value='' urlparam='' output='bootstrap']
	</div>

Vehicle Specifications
<div class="row">
	<div class="col-sm-6"><label>Make</label>
		[cred_field field='make' post='vehicle' value='' urlparam='' class='form-control' output='bootstrap']</div>
	<div class="col-sm-6"><label>Model</label>
		[cred_field field='model' post='vehicle' value='' urlparam='' class='form-control' output='bootstrap']</div>
</div>

<div class="hidden">
  [cred_field field='revision-author' post='vehicle' value='[wpv-current-user]' urlparam='']
  [cred_field field='revision-email' post='vehicle' value='[wpv-current-user info="email"]' urlparam='']
</div>

<br><br>

<div class="form-group">
		<label>Edit Summary (Briefly describe your changes)</label>
		[cred_field field='revision-summary' post='vehicle' value='' urlparam='' class='form-control' output='bootstrap']
	</div>

<div class="form-group">	
[cred_generic_field field='agree' type='checkbox' class='' urlparam='']
{
"required":1,
"validate_format":0,
"checked":0,
"default":"1",
"label":"By submitting this change you agree to our terms of use"
}
[/cred_generic_field]
 
  
[cred_show_group if="($(agree) eq  '1' )"  mode='fade-slide']
PLEASE NOTE - All changes are reviewed by a moderator before being posted live, which is usually done within 24 hours if not sooner. Thank you for contributing.
[/cred_show_group]
</div>

[cred_field field='form_submit' value='Submit for Review' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

[/credform]

Its this field here that I want to clear each time the form loads for contributors.

[cred_field field='revision-summary' post='vehicle' value='' urlparam='' class='form-control' output='bootstrap']

What is the link to your site?
Im working on localhost

Thanks guys, incredible piece of software you've put together.

#904535

I think you have the right idea, but I would set the value of the custom field to be ' ' - an empty space surrounded by quotation marks. Otherwise, the CRED engine will not recognize this as an attempt to override the default value. If you have validation for this field in the backend, you may need to adjust it to account for this empty space.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.