I created a cred form to accept user data to create a new CPT post. When I add it to a page via the cred form shortcode ( [cred_form form="content-add"] ) it works as expected. However, I need to push this cred form to the page via my own shortcode so I can run some conditionals and do some other stuff to decide exactly what to display. When I insert the cred form via the PHP cred_form function ( cred_form($form_id,$post_id); ) the form will display but when you submit it won't save the date and it reloads the page rather than submitting via ajax.
I loaded my page both ways and captured the full page source. Running it through winmerge shows me that when the cred_form shortcode is used the below javascript is included on the page. However, when I include the cred form via my PHP code it does not push to the page. The missing javascript seems to be the reason the cred_form via PHP does not work correctly.
<script type='text/javascript' src='<em><u>hidden link</u></em>;
<script type='text/javascript' src='<em><u>hidden link</u></em>;
<script type='text/javascript'>
/* <![CDATA[ */
var cred_frontend_i18n = {"ajaxurl":"https:\/\/exampledomain.gdn\/wp-admin\/admin-ajax.php","submit":{"action":"cred_submit_form","nonce":"4d567039c8"}};
/* ]]> */
</script>
<script type='text/javascript' src='<em><u>hidden link</u></em>;
<script type='text/javascript' src='<em><u>hidden link</u></em>;
<script type='text/javascript'>
/* <![CDATA[ */
var toolset_select2_i18n = {"errorLoading":"The results could not be loaded","inputTooLongSingular":"Please delete %NUM% character","inputTooLongPlural":"Please delete %NUM% characters","inputTooShort":"Please enter %NUM% or more characters","loadingMore":"Loading more results...","maximumSelectedSingular":"You can only select %NUM% item","maximumSelectedPlural":"You can only select %NUM% items","noResults":"No results found","searching":"Searching..."};
var toolset_select2_i18n = {"errorLoading":"The results could not be loaded","inputTooLongSingular":"Please delete %NUM% character","inputTooLongPlural":"Please delete %NUM% characters","inputTooShort":"Please enter %NUM% or more characters","loadingMore":"Loading more results...","maximumSelectedSingular":"You can only select %NUM% item","maximumSelectedPlural":"You can only select %NUM% items","noResults":"No results found","searching":"Searching..."};
/* ]]> */
</script>
<script type='text/javascript' src='<em><u>hidden link</u></em>;
<script type='text/javascript'>
/* <![CDATA[ */
var cred_select2_frontend_settings = {"ajaxurl":"https:\/\/exampledomain.gdn\/wp-admin\/admin-ajax.php","select2_fields_list":[],"cred_lang":""};
var cred_select2_frontend_settings = {"ajaxurl":"https:\/\/exampledomain.gdn\/wp-admin\/admin-ajax.php","select2_fields_list":[],"cred_lang":""};
/* ]]> */
</script>
<script type='text/javascript' src='<em><u>hidden link</u></em>;
My shortcode PHP code looks something like the following:
add_shortcode('show-some-content', 'do_something_func');
function do_something_func (){
$child_posts = types_child_posts('my-cpt');
$user_id = get_current_user_id();
$post_id = get_the_ID();
// Do some stuff
ob_start();
cred_form( '2610', $post_id);
$content = ob_get_clean();
return $content;
}
How can I get the javascript to enqueue to support the cred form when called via the PHP cred_form function? This seem to probably be the cause of the problem (at least that's my best guess right now).
Thanks!