I’m trying to generate a page with a form in a plugin. So I have this function
function create_form_page(){
if ( did_action( 'init' ) >= 2 )
return;
global $wpdb;
$page_content = '
<div style="margin:auto;">
<h1>تسجيل الدخول</h1>
<form name="contact_form" method="POST" enctype="multipart/form-data" autocomplete="off" accept-charset="utf-8" action="<?php echo admin_url( "admin-post.php" ); ?>" >
<label>ID *</label>
<input id="id" type="text" style="width:30%;" placeholder="please enter your id"/>
<button type="submit" style="margin-right:5%;" onclick="submitLogin()">Login</button>
</form>
</div>
';
$title = 'دخول الموظفين';
$slug = 'دخول-الموظفين';
$post_type = 'page';
$post = $wpdb->get_results("DELETE FROM $wpdb->posts WHERE post_title='$title'");
$page_args = array(
'post_type' => $post_type,
'post_title' => $title,
'post_content' => $page_content,
'post_status' => 'publish',
'post_author' => 1,
'post_slug' => $slug
);
if(!get_page_by_title($title, 'OBJECT', 'page')){
wp_insert_post($page_args);
}
}
but when I go to the page it’s not forming correctly, the form element is instead generated like this <form name="contact_form" method="POST" enctype="multipart/form-data" autocomplete="off" accept-charset="utf-8" action="<?php echo admin_url( " admin-post.php"="" );="" ?="">” ><br> <label>ID *</label><br> <input id="id" type="text" style="width:30%;" placeholder="please enter your id"><br> <button type="submit" style="margin-right:5%;" onclick="submitLogin()">Login</button><br> </form>
any ideas how can I prevent this?