1
I have the following problem, I have a shortcode that is a form, and inside this form have inputs that were created dynamically by the programmer himself through a function, but I have no idea how I will take the values of these inputs and save them in the bank? I’ll show you the codes.
shortcode function:
function register_users_shortcode(){
global $post;
?>
<div id="pando_cpt_formulario">
<form id="form" method="POST" ectype="multipart/form-data">
<p>
<label for="nome">Nome:</label>
<br />
<input type="nome" name="nome" id="nome" value="<?php echo get_post_meta( $post->ID, '_nome', true ); ?>" />
</p>
<p>
<label for="email">E-mail:</label>
<br />
<input type="email" name="email" id="email"value="<?php echo get_post_meta( $post->ID, '_email', true ); ?>" />
</p>
<p>
<label for="tel">Telefone:</label>
<br />
<input type="text" name="tel" id="tel" value="<?php echo get_post_meta( $post->ID, '_telefone', true ); ?>" />
</p>
<p>
<h2>Tipo de cadastro</h2>
Empregador <input type="radio" name="type_user" onclick="document.getElementById('empregador').style.display = 'block'; document.getElementById('trabalhador').style.display = 'none'"value="<?php echo get_post_meta( $post->ID, '_empregador', true ); ?>">
Trabalhador <input type="radio" name="type_user" onclick="document.getElementById('empregador').style.display = 'none'; document.getElementById('trabalhador').style.display = 'block'"value="<?php echo get_post_meta( $post->ID, '_Empregador', true ); ?>">
</p>
<div id="empregador" style="display:none">
<h3>Identificação do empregador</h3>
<strong>*Tipo de indentificação:</strong><br />
<?php echo register_render("tipo_id_empregador", "radio","tipo_id_empregador" ,array("CNPJ","CPF","CEI")); ?><br />
<strong>*Número de indentificação:</strong>
<?php echo register_render('numeroIdEmpregador','text'); ?>
<h3>Dados referente ao empregador</a></h3>
<strong>*Razão social:</strong>
<?php echo register_render('razaoSocialEmpregador','text'); ?>
<strong>*Nome fantasia:</strong>
<?php echo register_render('nomeFantasiaEmpregador','text'); ?>
<h3>Localização da empresa</h3>
<strong>*Logradouro:</strong>
<?php echo register_render('logradouroEmpregador','text'); ?>
</div>
<div id="trabalhador" style="display:none">
<h3>Indentificação do Trabalhador</h3>
<strong>*Número de Indentificação (PIS/PASEP/NIS/NIT)</strong>
<?php echo register_render('numeroIdTralhador','text'); ?> <br />
<strong>*Nome da mãe do trabalhador</strong>
<?php echo register_render('maeTrabalhador','text'); ?>
</div>
</form>
</div>
<?php }
add_shortcode('register_users_shortcode','register_users_shortcode');
dynamic input function:
<?php
function register_render($name,$type=null,$id=null,$value=null){
$types=array("text","email","password","radio");
if (is_null($type)){
$type = "text";
}
else {
if(!in_array($type,$types)){
exit("type inválido");
}
}
switch ($type) {
case 'text':
return "<input type='$type' name='$name' value='".get_post_meta( $post->ID, "_$name", true )."' id='$name'>";
break;
case 'email':
return "<input type='$type' name='$name' value='".get_post_meta( $post->ID, "_$name", true )."' id='$name'>";
break;
case 'password':
return "<input type='$type' name='$name' value='".get_post_meta( $post->ID, "_$name", true )."' id='$name'>";
break;
case 'radio':
return register_radio($name,$value);
break;
default:
return "error register render - invalid type";
break;
}
}
function register_radio($name,$var){
$result = '';
foreach ($var as $option){
$result .= "<input type='radio' name='$name' value='".get_post_meta( $post->ID, "_$option", true )."' id='$name'> $option";
}
return $result;
}
wouldn’t it be easier to create a custom post type
– Otto
I don’t want to create inputs in the admin area, I want in a page for any user to register.
– Any Karolyne Galdino
So you want to take the values of the fields generated dynamically ?
– Silvio Andorinha
exactly that Silvio
– Any Karolyne Galdino