Re: PHP generated HTML has submit button which picks up the wrong url.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"What you maybe ought to consider is using several submit buttons, and give each a name and a value. That way, your PHP script can check for a specifically named variable sent from the form. That way, you keep many people happy, and your site still works perfectly."

The problem with doing it that way is that IE is not happy with multiple submit buttons in a single form. To get around that, you can use image input types or buttons. Also, a return key does not send values the same way as a mouse click. I can't remember which browser does what, but the three possible submitted values are (providing the name of the button is submit):

submit
submit_x and submit_y
submit_x, submit_y, and submit

Just something to be aware of if you are looking for the value of the submit button -- not 100% reliable. It would be better to use a hidden form value or just check to see if submit or submit_x is set.

Joseph

Ashley Sheridan wrote:
On Fri, 2010-02-05 at 14:33 -0600, Joseph Thayne wrote:
This is actually a javascript issue rather than a PHP issue. What is happening is that the action of the form is what is being submitted. The action never changes. What you need to do is have the javascript change the action as well as submit the form (which means you will need to move it to a function). It would also help to empty out the form action as well.

Example JS function:
function retrieveAllPerm()
{
document.display_data.action='http://unproto.demog.berkeley.edu/memdemo/edit_query_form.php?perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries' <http://unproto.demog.berkeley.edu/memdemo/edit_query_form.php?perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries%27>;
document.display_data.submit();
}

Example submit button:
<button name='edit_existing_query_form' onClick="javascript:retrieveAllPerm();" >Revise query</button>

Joseph

Mary Anderson wrote:
> Hi,
> I am writing code in PHP which generates HTML script. My app is > fairly complex. Twice in the development of the application I have > run into a problem with submit buttons which pick up the wrong url. > Instead of call the url for that submit button, it appears to call the > url for the first submit button on the page. The problem may be > intermittent, which seems to suggest that something funny is happening > with the cache. Clearing the cache did not help in the last go around. > I am including the generated html code. Hitting the button 'Retrieve > all ...' should call up the url get_query_forms.php. Instead it calls > up the url query_form_display_data.php, which is the url for the first > submit button on the page.
>
>   Any clues to clear up this mystery would be greatly appreciated!
>
> Mary Anderson
>
> ------------------------------------------------------------------------
>
>
>
>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <LINK href="./DMEM.css" type=text/css rel=stylesheet>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> <title>Display Data</title>
> </head>
> <body> <form id="display_data" name="display_data" method="POST" > action=./query_form_display_data.php?perm_batch_file=perm&pg_query_form_id=518&data_table_id=255&data_batch_id=&query_form_schema=permanent_queries&batch_input_file_id=&create_tmp_data_tables=0"> >
>
> <p >
> <big>72 rows have been returned by this query</big>
> </p><br>
> <p >
>
> <table >
>
> <tr >
>
> <th >
>
> </th>
>
> <td >
> <input type='text' name='max_row_count' size='3' value='0' ></input>
>
> </td>
>
> </tr>
>
> </table>
> <br><br>
> <p >
> <input type='submit' name='worksheet_join_element_initialize' > value='Change worksheet : Change max row count' > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries' <http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries%27>" > ></input> > <input type='submit' name='display_results' value='Display query > results' > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries' <http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries%27>" > ></input> > <input type='submit' name='generate_csv_file' value='Generate csv > file' > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries' <http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries%27>" > ></input>
>
> <p >
> <input type='submit' name='edit_existing_query_form' value='Revise > query' > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/edit_query_form.php?perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries' <http://unproto.demog.berkeley.edu/memdemo/edit_query_form.php?perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries%27>" > ></input> > <input type='submit' name='retrieve_existing_query_forms' > value='Retrieve all permanent query forms for this table type' > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/get_query_forms.php?perm_batch_file='perm'&query_form_schema=permanent_queries&user_name=&data_table_type_id=' <http://unproto.demog.berkeley.edu/memdemo/get_query_forms.php?perm_batch_file=%27perm%27&query_form_schema=permanent_queries&user_name=&data_table_type_id=%27>" > ></input> > <input type='submit' name='retrieve_existing_query_forms' > value='Retrieve all temporary query forms for this table type' > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/get_query_forms.php?perm_batch_file='perm'&query_form_schema=temporary_queries&user_name=&data_table_type_id=' <http://unproto.demog.berkeley.edu/memdemo/get_query_forms.php?perm_batch_file=%27perm%27&query_form_schema=temporary_queries&user_name=&data_table_type_id=%27>" > ></input> > <input type='submit' name='select_table_type' value='Change data > table type' > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/get_query_forms.php?perm_batch_file=perm&user_name=' <http://unproto.demog.berkeley.edu/memdemo/get_query_forms.php?perm_batch_file=perm&user_name=%27>" > ></input>
>
> </p>
> <p >
> <input type='submit' name='home' value='Home' > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo' <http://unproto.demog.berkeley.edu/memdemo%27>" > ></input>
>
> </p><input type='hidden' id='perm_batch_file' name='perm_batch_file' > value='perm'><input type='hidden' id='tmp_data_values_table' > name='tmp_data_values_table' > value='display.perm_tmp_data_values_518'><input type='hidden' > id='pg_query_form_id' name='pg_query_form_id' value='518'><input > type='hidden' id='query_form_schema' name='query_form_schema' > value='permanent_queries'><input type='hidden' id='data_table_id' > name='data_table_id' value='255'><input type='hidden' > id='data_batch_id' name='data_batch_id' value='218'><input > type='hidden' id='batch_input_file_id' name='batch_input_file_id' > value=''><input type='hidden' id='tf_directory' name='tf_directory' > value=''><input type='hidden' id='tf_filename' name='tf_filename' > value=''><input type='hidden' id='data_table_type_id' > name='data_table_type_id' value=''><input type='hidden' id='user_name' > name='user_name' value=''></form>
> </body>
> </html>
>
>


Bit of advice though, don't use Javascript to submit a form. Firstly, Javascript isn't available on all browsers, and on those it is available on, not everyone has it turned on. The W3C has the stats for Javascript being unavailable in a browser at about 5%. Imagine that your site is only aimed at the population of the UK, 5% of 61 million is still over 3 million people. Obviously that doesn't take into consideration the ages of people who'd be using your site, but it's worth stopping and thinking about. Also, anyone using a mobile is unlikely to have Javascript enabled too, and a lot of people use mobiles these days for browsing and such whilst on the move.

Secondly, you're using the onclick handler to submit a form. This is very bad, as you totally alienate anyone who visits your site that has a disability that prevents them using a mouse. So, anyone with hand problems like severe arthritis or missing hands, or anyone who is blind is shut out from your site.

What you maybe ought to consider is using several submit buttons, and give each a name and a value. That way, your PHP script can check for a specifically named variable sent from the form. That way, you keep many people happy, and your site still works perfectly.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux