Re: [PHP] PHP generated HTML has submit button which picks up the wrong url.
[email protected] (Joseph Thayne)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
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';
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'"
> ></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'"
> ></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'"
> ></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'"
> ></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='"
> ></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='"
> ></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='"
> ></input>
>
> </p>
> <p >
> <input type='submit' name='home' value='Home'
> onClick="form.action='http://unproto.demog.berkeley.edu/memdemo'"
> ></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>
>
>