Como faço pra jogar um valor de um input, sem submeter um form ou botão

Olá, queria pegar o valor do input "codigo_cat" e jogar na variável $ id_categoria que está em baixo no código PHP, pra conseguir rodar o select usando esta variável como parâmetro. Por método GET E POST eu conseguiria fazer, o problema é que eu não estou submetendo nenhum form ou botão, para que um método seja usado.

Tem como fazer isso? Se alguém souber me ajude. Estou a 2 dias tentando fazer isso! Obrigado.

<div class="row">     <div class="col-md-3">         <div class="form-group">             <label for="codigo">Código</label>             <input name="codigo" id="codigo_cat" type="text" class="form-control form-control-sm" placeholder="0" readonly>         </div>     </div> </div>  <div class="row">     <div class="col-md-12">         <?php              $  id_categoria = (QUERO O VALOR DO INPUT AQUI);              $  query = "SELECT ativo AS ativo_status FROM categoria WHERE idCategoria = '$  id_categoria'";             $  result = mysqli_query($  conexao, $  query);             $  row = mysqli_fetch_assoc($  result);              if ($  row['ativo_status'] == 'S') {         ?>             <input type="checkbox" id="ativo" name="ativo" checked>         <?php             } else {         ?>             <input type="checkbox" id="ativo" name="ativo">         <?php             }         ?>          <label for="ativo">Ativo</label>     </div> </div> 

Submeter form com campo nulo ao invés de vazio

Estou utilizando Spring-data e Thymeleaf na minha aplicação, e quando tento submeter um formulário com campo do tipo Date sem preenchê-lo, obtenho o seguinte erro:

Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date’…

Acredito que é por causa do form enviar o campo data com valor vazio ao invés de nulo. Existe a possibilidade de enviar o valor nulo ao invés de vazio?

Segue alguns trechos do meu código: Classe person:

@Entity @Table(name = "person") public class Person implements Serializable, EnableDisable, GenerateId{      private static final long serialVersionUID = -7232054300548386801L;      @Id     @Column(name = "person_id")     private String personId;      @Column(name = "cpf")     @Length(min=14, message="{person.min.value.cpf}")     @Length(max=14, message="{person.max.value.cpf}")     private String cpf;      @Column(name = "name")     @NotEmpty(message = "{person.empty.value.name}")     @Length(min=3, message="{person.min.value.name}")     @Length(max=255, message="{person.max.value.name}")     private String name;      @Column(name = "last_name")     @NotEmpty(message = "{person.empty.value.lastname}")     @Length(min=3, message="{person.min.value.lastname}")     @Length(max=255, message="{person.max.value.lastname}")     private String lastName;      @Column(name ="date_of_birth",nullable = true)     @Temporal(TemporalType.DATE)     private Date dateOfBirth;      @Column(name = "active")     private boolean active;      @Column(name = "dweller")     private boolean dweller; //morador      @Column(name = "owner")     private boolean owner; //proprietário      @Column(name = "renter")     private boolean renter; //locatário      @Column(name = "managerCondo")     private boolean managerCondo; //Síndico      //relationship     @ManyToMany(cascade = CascadeType.ALL)     @JoinTable(name = "person_telephone", joinColumns = @JoinColumn(name = "person_id"), inverseJoinColumns = @JoinColumn(name = "telephone_id"))     private List<Telephone> telephones;      //relationship     @ManyToMany(cascade = CascadeType.ALL)     @JoinTable(name = "person_address", joinColumns = @JoinColumn(name = "person_id"), inverseJoinColumns = @JoinColumn(name = "address_id"))     private List<Address> addresses;      @OneToOne(fetch = FetchType.LAZY)     @JoinColumn(name="user_id", referencedColumnName="user_id")     private User user;       public String getPersonId() {         return personId;     }      public String getCpf() {         return cpf;     }      public void setCpf(String cpf) {         this.cpf = cpf;     }      public String getName() {         return name;     }      public void setName(String name) {         this.name = name;     }      public String getLastName() {         return lastName;     }      public void setLastName(String lastName) {         this.lastName = lastName;     }      public boolean isActive() {         return active;     }      public void setActive(boolean active) {         this.active = active;     }      public boolean isDweller() {         return dweller;     }      public void setDweller(boolean dweller) {         this.dweller = dweller;     }      public boolean isOwner() {         return owner;     }      public void setOwner(boolean owner) {         this.owner = owner;     }      public boolean isRenter() {         return renter;     }      public void setRenter(boolean renter) {         this.renter = renter;     }      public boolean isManagerCondo() {         return managerCondo;     }      public void setManagerCondo(boolean managerCondo) {         this.managerCondo = managerCondo;     }      public List<Telephone> getTelephones() {         return telephones;     }      public void setTelephones(List<Telephone> telephones) {         this.telephones = telephones;     }      public List<Address> getAddresses() {         return addresses;     }      public void setAddresses(List<Address> addresses) {         this.addresses = addresses;     }      public User getUser() {         return user;     }      public void setUser(User user) {         this.user = user;     }      public Date getDateOfBirth() {         return dateOfBirth;     }      public void setDateOfBirth(Date dateOfBirth) {         this.dateOfBirth = dateOfBirth;     }      public Person() {         enable();         generateId();         this.telephones = new ArrayList<Telephone>();         this.addresses = new ArrayList<Address>();     }      @Override     public void generateId() {         if(this.personId == null) {             this.personId = UUID.randomUUID().toString();         }     }      @Override     public void enable() {         this.active = true;          }      @Override     public void disable() {         this.active = false;     } } 

minha página html:

<form class="col s12" method="post" th:object="$  {person}">     <div class="card-panel">         <label class="" th:text="#{person-data}"></label>         <div class="card-panel">             <div class="row">                 <div class="input-field col s12 m6 l6">                     <input type="hidden" readonly="readonly" th:field="*{personId}" />                     <input id="first_name" type="text" class="validate" th:field="*{name}">                     <label for="first_name" th:text="#{first-name}"></label>                     <span th:if="$  {#fields.hasErrors('name')}" th:errors="*{name}" class="validation-message"></span>                 </div>                 <div class="input-field col s12 m6 l6">                     <input id="last_name" type="text" class="validate" th:field="*{lastName}">                     <label for="last_name" th:text="#{last-name}"></label>                     <span th:if="$  {#fields.hasErrors('lastName')}" th:errors="*{lastName}" class="validation-message"></span>                 </div>             </div>             <div class="row">                 <div class="input-field col s12 m5 l5">                     <i class="material-icons prefix">email</i>                     <input id="managerCondo-email" type="text" class="validate" th:field="*{user.email}">                     <label for="managerCondo-email" th:text="#{email}"></label>                     <span th:if="$  {#fields.hasErrors('user.email')}" th:errors="*{user.email}" class="validation-message"></span>                 </div>                 <div class="input-field col s12 m5 l5">                     <i class="material-icons prefix">cake</i>                      <input type="text" class="datepicker validate" th:field="*{dateOfBirth}">                     <label for="dateOfBirth" th:text="#{date.birth}"></label>                     <span th:if="$  {#fields.hasErrors('dateOfBirth')}" th:errors="*{dateOfBirth}" class="validation-message"></span>                 </div>             </div>         </div>          <label th:text="#{address}"></label>         <div th:replace="/fragments/addresses::addresses"></div>         <label th:text="#{condo-telephones}"></label>         <div th:replace="/fragments/telephones::telephones"></div>          <div th:replace="/fragments/buttons::button-save-person-profile"></div>     </div> </form> 

O erro ao enviar o form com o campo data vazio

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.  Sun Jul 28 22:16:56 BRT 2019 There was an unexpected error (type=Bad Request, status=400). Validation failed for object='person'. Error count: 1 org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object 'person' on field 'dateOfBirth': rejected value []; codes [typeMismatch.person.dateOfBirth,typeMismatch.dateOfBirth,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [person.dateOfBirth,dateOfBirth]; arguments []; default message [dateOfBirth]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'dateOfBirth'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Column @javax.persistence.Temporal java.util.Date] for value ''; nested exception is java.lang.IllegalArgumentException]     at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:164)     at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:126)     at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:166)     at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892)     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)     at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)     at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)     at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:320)     at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)     at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     at org.springframework.security.web.FilterChainProxy$  VirtualFilterChain.doFilter(FilterChainProxy.java:334)     at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)     at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)     at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)     at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)     at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)     at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)     at org.apache.coyote.AbstractProtocol$  ConnectionHandler.process(AbstractProtocol.java:834)     at org.apache.tomcat.util.net.NioEndpoint$  SocketProcessor.doRun(NioEndpoint.java:1415)     at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)     at java.util.concurrent.ThreadPoolExecutor$  Worker.run(Unknown Source)     at org.apache.tomcat.util.threads.TaskThread$  WrappingRunnable.run(TaskThread.java:61)     at java.lang.Thread.run(Unknown Source) 

Submeter dados p/ base dados via SOCK_STREAM

Olá, preciso de criar uma função que deverá fazer a ligação ao porto 80 do servidor “servername” proceder ao envio de um pedido em que a lista de parâmetros/valores do pedido POST é definida com base nos parâmetros dela. Só que após a execução da função, o valor inserido nos parâmetros não está sendo inserido no formulário (PHP) do servidor, mesmo que estejam contidos no buffer.

#include <netdb.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h>  int my_connect(char *servername, char *port); void recv_server_reply(int s); void submeter_dados(char *servername, char *uri, char *plate, char *owner, double value);  char http_msg[] =      "POST %sHTTP/1.1\r\n"     "Host: %s\r\n"     "Content-Type: application/x-www-form-urlencoded\r\n"     "Content-Length: %ld\r\n"     "Connection: close\r\n"     "\r\n"     "%s";  int main (int argc, char* const argv[]) {    //enviar dados   submeter_dados("servidor.pt", "/ficheiro/redirecionado/peloformulario", "PL1819", "John", 5000.0);    return 0; }   void recv_server_reply(int s)  {   char buf[4096];    printf("Reply from server: ");   while(1)    {     int n = read(s, buf, 1);     if(n <= 0)       break;     putchar(buf[0]);     fflush(stdout);     if(buf[0]=='\n')       printf(": ");   }     printf("\n\n"); }   int my_connect(char *servername, char *port) {    //get server address using getaddrinfo   struct addrinfo hints;   struct addrinfo *addrs;   memset(&hints, 0, sizeof(struct addrinfo));   hints.ai_family = AF_INET;   int r = getaddrinfo(servername, port, &hints, &addrs);   if (r != 0) {     fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(r));     exit(1);   }    //create socket   int s = socket(AF_INET, SOCK_STREAM, 0);   if (s == -1) {     perror("socket");       exit(2);   }    //connect to server   r = connect(s, addrs->ai_addr, addrs->ai_addrlen);   if (r == -1) {     perror("connect");       close(s);     exit(3);   }    return s; }  void submeter_dados(char *servername, char *uri, char *plate, char *owner, double value){     int sd = my_connect(severname, "80");      char params[4096];     char buffer[1000];     sprintf(params, "plate=%.6s&owner=%s&value=%.2lf", plate, owner, value);     snprintf(buffer, sizeof(buffer), http_msg, uri, servername, strlen(params), params);      write(sd, buffer, strlen(buffer));      recv_server_reply(sd); } 

Obrigado pela ajuda!