edit $_POST values before posting into database
Author | Posts |
---|---|
April 11, 2013 at 12:06 am 2013 | |
Sparhamster | Another (and last ;)) question:
i have to edit a special form field before adding it to the database. in which part of the content i have to insert the code?
for example:
|
April 11, 2013 at 12:51 am 2015 | |
Tareq Hasan | The default category topic may be enough for the code example. You might checkout the documentation. |
April 11, 2013 at 11:17 pm 2055 | |
Sparhamster | can u tell me, why it works with $_POST and not with the parameter $postarr? function wpuf_editpostdata( $postarr ) { $_POST[‘Preis’] = str_replace(“,”, “.”, $_POST[‘Preis’]); return $postarr; add_filter( ‘wpuf_add_post_args’, ‘wpuf_editpostdata’ ); it is possible to print_r in functions? every time i try to print_r an array like postarr, the site ist loading and loading 😉 and i try in that line: array_push($_POST[‘Kategorie’], “1”); to add the category id 1 to the category array..it does’t work. which function i have to choose? |
April 12, 2013 at 1:18 am 2058 | |
Tareq Hasan |
If you are printing something, that means it’s modifying the ajax response. And that breaks the JSON response, so it keeps loading. |
April 12, 2013 at 4:55 am 2072 | |
Sparhamster | like that? function wpuf_editpostdata( $form_vars ) { $form_vars[‘Preis’] = str_replace(“,”, “.”, $form_vars[‘Preis’]); return $form_vars; add_filter( ‘wpuf_add_post_after_insert’, ‘wpuf_editpostdata’ ); but it didn’t work … $form_vars[‘Preis’] & $form_vars[‘Stattpreis’] are costum fields of the form. can u show me how the $form_vars oder $form_settings array is build? |
April 12, 2013 at 10:36 am 2079 | |
Tareq Hasan | Here is the correct approach: add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_edit_postdata’ ); The difference between action and filter is, action doesn’t need/care about return value where filter is for modifying the value and return it. |
April 12, 2013 at 3:22 pm 2105 | |
Sparhamster | thx for the great support and the best form plugin for wp 😉 |