Go Down

Topic: [SOLVED] Number/Hash sign in URL after submitting form (Read 1 time) previous topic - next topic


Feb 04, 2013, 10:33 pm Last Edit: Feb 05, 2013, 09:32 pm by mtruijen Reason: 1
Hello Arduino gurus.

I have developed a small program that will read the request header and returns a response header and message to client.

Everything works great except one small annoying thing.

When I submit the form, it appends a number/hash symbol to the URL. I have set the form action to post to itself (method is POST).

Please check it out here: http://arduino.martin.us.com

Any help would be highly appreciated.


Seemed ok from here. Maybe you should post your code.


In order to reproduce, you would have to submit the page a couple times...

Coding Badly

First, I suggest you fix the HTML problems...

Maybe that will resolve the hash problem.


Great suggestion to run it through a validator. Some embarrassing mistakes. Got them fixed. Still the same issue ...


Feb 05, 2013, 08:54 am Last Edit: Feb 05, 2013, 09:36 am by Coding Badly Reason: 1
Here's my code:

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,20);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

const char* iContentLengthPtr;
const char* kContentLengthPrefix = "Content-Length: ";

typedef enum {
} tHttpState;

int laserPin = 9;

void setup() {

 // Open serial communications and wait for port to open:

 // start the Ethernet connection and the server:
 Ethernet.begin(mac, ip);

 // initialize the digital pin as an output.
 pinMode(laserPin, OUTPUT);    


void loop() {

 tHttpState iState = eStatusCodeRead;
 int iContentLength = 0;
 int iElementCount;
 iContentLengthPtr = kContentLengthPrefix;

 char e[2][16];
 char *element;

 // listen for incoming clients
 EthernetClient client = server.available();
 if (client) {

   // client.available() returns the number of bytes the client has yet to return
   // This number decreases everytime we do a client.read()
   while (client.available() > 0) {

       char c = client.read();

       switch(iState) {

         case eStatusCodeRead:
           if (*iContentLengthPtr == c) {
             if (*iContentLengthPtr == '\0') {
               iState = eReadingContentLength;
           } else {
             iContentLengthPtr = kContentLengthPrefix;

         case eReadingContentLength:
           if (isdigit(c)) {
             iContentLength = iContentLength*10 + (c - '0');
           } else {
             iState = eSkipToStartOfBody;

         case eSkipToStartOfBody:
           if (client.available() <= iContentLength) {
             iState = eReadingBody;
             iElementCount = 0;
         case eReadingBody:
             if (c == '=') {
               memset(e[iElementCount], 0, 16);
               element = e[iElementCount];
               iState = eReadFormElement;

         case eReadFormElement:
           if (c != '&') {
             *element++ = c;
           } else {
             iState = eReadingBody;



   if (strcmp(e[1],"on") == 0) {
     digitalWrite(laserPin, HIGH);
   } else {
     digitalWrite(laserPin, LOW);

   client.println("HTTP/1.1 200 OK");
   client.println("Content-Type: text/html charset=utf-8");
   client.println("Connnection: close");
   client.println("<!DOCTYPE html>");
   client.println("<meta charset=\"UTF-8\">");
   client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
   client.println("<link rel=\"stylesheet\" href=\"http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css\" />");
   client.println("<script src=\"http://code.jquery.com/jquery-1.8.2.min.js\"></script>");
   client.println("<script src=\"http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js\"></script>");
   client.println("<title>Martien's Arduino</title>");
   client.println("<div data-role=\"page\">");
   client.println("<div data-role=\"header\">");
   client.println("<div data-role=\"content\">");
   client.println("<form method=post action=\"http://arduino.martin.us.com/\">");
   client.println("<fieldset data-role=\"fieldcontain\">");
   client.println("<label for=\"flip-1\">Laser</label>");
   client.println("<select name=\"flip-1\" id=\"flip-1\" data-role=\"slider\" data-mini=\"true\">");
   client.write("<option value=\"off\"");
     if(!bitRead(PORTB, 1)) client.write(" selected");
   client.write("<option value=\"on\"");
     if(bitRead(PORTB, 1)) client.write(" selected");
   client.println("<input type=submit value=Submit />");


Moderator edit: [code] [/code] tags added.

Coding Badly

When I submit the form, it appends a number/hash symbol to the URL.

jQuery appears to be the culprit.


Oh really? Thanks so much for finding that out. I will see if I can figure out what in JQuery is causing this.


Added data-ajax="false" to the form element and issue was resolved  :)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131