Set default value for field
-
How to set default value for text field and select field, if not yet been filled before?
I tried this, but when user already filled the value and click ‘edit ad’ in preview. It will return to default value instead of user’s filled value:
add_filter( "adverts_form_load", "default_value_adverts_location" ); function default_value_adverts_location( $form ) { if( $form['name'] != "advert" ) { return $form; } foreach( $form["field"] as $key => $field ) { if( in_array($field["name"], array( "adverts_location" ) ) ) { $form["field"][$key]["attr"] = array( "value" => "Chicago", ); } } return $form; }Update:
Maybe its not possible in php? Im thinking to add it via javascript instead. But how to only add script on “adverts_add” page?Is there any function similar like is_search / is_archive in wpadverts? so we know which page we currently in.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Set default value for field’ is closed to new replies.