I am building a Wordpress plugin for a file cataloging project, basically it consists in creating a table and a form that can be used by collaborators to fill information related to certain documents. I'm not very proficient in programming so it has cost me some work, that's why I turn to your help.
The idea is that the plugin can create a new table in the wordpress database, which it does without problems:
global $neog_db_version;
$neog_db_version = '1.0';
function neog_install (){
global $wpdb;
$table_name = $wpdb->prefix . "ng_catalogacionprimaria";
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
fecharegistro datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
identificaciondoc text NOT NULL,
titulodoc text NOT NULL,
descripcion text NOT NULL,
lugar text NOT NULL,
personas text NOT NULL,
etiquetas text NOT NULL,
anotaciones text NOT NULL,
post_author bigint(20),
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql);
add_option( 'neog_db_version', $neog_db_version );
}
register_activation_hook( __FILE__, 'neog_install' );
The problem is in the form. The idea is that through a shortcode I can integrate it in the pages that are published, however I have not achieved it.
function form_creation()
{
global $wpdb;
ob_start();
?>
<form action="#v_form" method="post" id="neog_form">
<h3>Formulario</h3><br>
Identificación de documento: <input type="text" name="identificaciondoc" id="identificaciondoc"><br>
Fecha: <input type="date" name="fecha" id="fecha"><br>
Título del documento: <input type="text" name="titulodoc"><br>
Descripción: <textarea name="descripcion">Descripción extensa del documento</textarea><br>
Lugar: <input type="text" name="lugar"><br>
Personas: <textarea name"personas"> Nombres de personas según formato aconsejado: Nombres Apellidos (empleo, calidad) separados por un signo + </textarea><br>
Etiquetas: <input type="text" name="etiquetas"><br>
Anotaciones: <textarea name="anotaciones"> Anotaciones sobre las imágenes (por ejemplo, imagenes de escala o ilegibles). Indicar folios en blanco, deteriorados, desenfocados.</textarea><br>
<input type="submit" name="submit_form" value="submit" onclick="window.location.reload(true)" />
</form>
<?php
$html = ob_get_clean();
if ( isset( $_POST["submit_form"] )) {
$table_name = $wpdb->prefix . "ng_catalogacionprimaria";
$identificacion = $_POST['identificaciondoc'];
$fecha = $_POST['fecha'];
$titulodoc = $_POST['titulodoc'];
$descripcion = $_POST['descripcion'];
$lugar = $_POST['lugar'];
$personas = $_POST['personas'];
$etiquetas = $_POST['etiquetas'];
$anotaciones = $_POST['anotaciones'];
$wpdb->insert(
$table_name,
array(
'fecharegistro' => current_time( 'mysql' ),
'identificacion' => $identificacion,
'fecha' => $fecha,
'titulodoc' => $titulodoc,
'descripcion' => $descripcion,
'lugar' => $lugar,
'personas' => $personas,
'etiquetas' => $etiquetas,
'anotaciones' => $anotaciones,
)
);
}
}
add_shortcode('neogranada', 'form_creation');
The table in the database is created but the shortcode when publishing the page does not show me anything. Any indication I thank you.