• Resolved Fody

    (@fodisery)


    Lets say I want to make:
    -) title automatically become uppercase for each word. (in php we use ucwords() )
    -) if phone is not empty, convert it to international format (I already have the function to convert number to international format)

    How to do it, so during preview and saved, this value changed the way i wanted?

    Maybe using ‘adverts_form_bind’? But I dont know why this filter is called multiple times during single page load. this filter also run on advert add form.

Viewing 1 replies (of 1 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    You want to customize the user input before the validation, you can do that with the form filters.

    See the Filters section here https://wpadverts.com/doc/forms-api/ it shows how to register new filters with adverts_form_add_filter function.

    Once you have the filters you can apply them to fields with the adverts_form_load filter

    
    add_filter( "adverts_form_load", function( $form ) {
      if( $form["name"] != "advert" ) {
        return $form;
      }
      foreach( $form["field"] as $k => $f ) {
        if( $f["name"] == "post_title" ) {
          $form["field"][$k]["filter"] = array( array( "name" => "ucwords_filter" ) );
        }
      }
      return $form;
    } );
    

    where the ucwords_filter is the actual name of the filter you registered for changing the words case earlier.

    Similarly in the foreach loop you can add filters for the adverts_phone and other fields.

Viewing 1 replies (of 1 total)
  • The topic ‘How to replace form value before preview and save?’ is closed to new replies.