473,883 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form with 2 submit buttons...

Hi all!

I have a file where I'd have to submit buttons, and I need to differ
between those.

Step #1 - open html win with default selection

Step #2 - user may select some criteries for the list
Step 2 might be repeated, or not used at all. There is a button "apply
selection"

Step #3 - user selects a number of files/items, which are then handled.
There is a button for that.
Done.

The point is, that I need both the critearies for the SQL selection in
step 2, but also the selected files (list) in step 3. Actually the
selection for step 2 are needed for step 3 only.

Any good ideas on how I might have 2 buttons with submits data?

BR
Sonnich

Aug 7 '06
15 8853
Sonnich wrote:
>
<html>
<form method=post name='myform' action='sjjtest .php'><!-- same file -->
<table>
<?
$part1[]="a";
$part1[]="b";
$part1[]="c";
for($i=0; $i<count($part1 ); $i++)
{
echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox \"
value=\"true\"" ;
if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
echo " checked";
echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
."</td></tr>";
}
?>
<tr><td><inpu t class="box" name="apply_sel ection" type="submit" value="
Apply selection "></td></tr>
</table>
</form>
</html>

Try it and you will see
Not sure what you are trying to accomplish here but in PHP block
statements need to be surrounded by braces {} therefore it think your
PHP part should be:
<?
$part1[]="a";
$part1[]="b";
$part1[]="c";
for($i=0; $i<count($part1 ); $i++)
{
echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox \"
value=\"true\"" ;

if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
{ //needed open brace
echo " checked";
} //closing brace

echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
.."</td></tr>";
}
?>
But again not sure what your aim is here....

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Aug 7 '06 #11
Jonathan N. Little wrote:
Sonnich wrote:
>>
<html>
<form method=post name='myform' action='sjjtest .php'><!-- same file -->
<table>
<?
$part1[]="a";
$part1[]="b";
$part1[]="c";
for($i=0; $i<count($part1 ); $i++)
{
echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox \"
value=\"true\" ";
if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
echo " checked";
echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
."</td></tr>";
}
?>
<tr><td><inp ut class="box" name="apply_sel ection" type="submit" value="
Apply selection "></td></tr>
</table>
</form>
</html>

Try it and you will see

Not sure what you are trying to accomplish here but in PHP block
statements need to be surrounded by braces {} therefore it think your
PHP part should be:
<?
$part1[]="a";
$part1[]="b";
$part1[]="c";
for($i=0; $i<count($part1 ); $i++)
{
echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox \"
value=\"true\"" ;

if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
{ //needed open brace
echo " checked";
} //closing brace

echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
."</td></tr>";
}
?>
But again not sure what your aim is here....
Actually since the body of the if statement is a single statement, the
braces are optional. Only if you have multiple statements in the body
of a loop, if, else, etc. are braces required.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 7 '06 #12
Sonnich wrote:
Jonathan N. Little wrote:
>>Sonnich wrote:

[You are improperly snipping who wrote what quote which can get quite
confusing, try to keep or replace quoted author notices which I have
restored to show you....]

>Sonnich wrote:
>>>>>I found that it should work here too:
>
if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
>"")) )
echo " checked";
else
echo "";
>
>Idea: checkbox is default checked, but only if set and set to nothing
>it is not set.
>Boolean algebra. Only if set, and set to nothing, then it is not set.
>
>But by some reason it does not work. I have done this a 147533 times,
>and here it does not work. Why?
>
Jonathan wrote:
>>>>I think a misplaced closing parentheses:
You were right. This is what I have now:

if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] ==
"") )
echo " checked";
else
echo "";

but is still does not work. It sets them first time as it should, but
after that it inverts the selection.
I dont get it.

Any ideas anyone?

Not enough info to determine, need URL and your source code. What you
you me by 'sets them'? Sets what? And 'after the first time'? Are your
reposting to the same script?


Yes, I am reposting to the same script. An example:
<html>
<form method=post name='myform' action='sjjtest .php'><!-- same file -->
<table>
<?
$part1[]="a";
$part1[]="b";
$part1[]="c";
for($i=0; $i<count($part1 ); $i++)
{
echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox \"
value=\"true\"" ;
if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
echo " checked";
echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
."</td></tr>";
}
?>
<tr><td><inpu t class="box" name="apply_sel ection" type="submit" value="
Apply selection "></td></tr>
</table>
</form>
</html>

Try it and you will see
If you had all errors enabled and were displaying them, you would have
found errors in both statements with isset():

Notice: Undefined index: a in myform.php on line 10

In the first one your parens were set so that you were checking $_POST
whether or not the particular index was set. In the second one the
value in $_POST is always checked, whether it is valid or not.

The following code does what you want:

<?php
$part1[]="a";
$part1[]="b";
$part1[]="c";
for($i=0; $i<count($part1 ); $i++)
{
echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox \"
value=\"true\"" ;

if( (isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] != "") ))
echo " checked";

echo ">". (isset($_POST[$part1[$i]]) ? "-" . $_POST[$part1[$i]] :
"" ) . "</td></tr>";
}
?>
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 8 '06 #13
"Sonnich" <so************ @elektrobit.com wrote:
Miguel Cruz wrote:
>"Sonnich" <so************ @elektrobit.com wrote:
>>if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] == "")) )

Are you sure you want $_POST[$part1[$i]] ? Maybe $_POST[$part1][$i] ?

Hard to know without understanding how your form and code look, but my
proposed alternative is more typical for dealing with checkboxes.

If I am correct in my theory, turning on E_ALL error reporting would
have drawn attention to the issue.

I have a number of checkboxes, which are created from a DB. I read a
number of codes into an array $part1[]= then I create the checkboxes
Name=\"$part1[$i]] \" and at the same time set them to checked or not.
At first they should be checked, but the user can select to uncheck
them. Then, when submitting the now present values should be in use.
In that case you definitely want $_POST[$part1][$i] .

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Aug 8 '06 #14

Rik wrote:
Sonnich wrote:
<?
$part1[]="a";
$part1[]="b";
$part1[]="c";
for($i=0; $i<count($part1 ); $i++)
{
echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox \"
value=\"true\"" ;
if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
echo " checked";
echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]

Euhm, what it this last bit
'isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]' actually supposed to do?
It will either print '1-true' or ''(nothing)?
That was meant as debugging :-)
>
."</td></tr>";
}


You've got a submit button, it's name is in the POST array, so it should be
present if the form is posted. Before posting, everything should be checked.
After the posting only the previously left checked values should be checked,
the rest unchecked. Is that how it should work? in that case:
Almost.
In case of any new items, they should be checked too.

There are other options, which might change sql query and by that the
array, so we have new items. They should be selected by default when
they appear.
Otherwise I found this useful.

I'll have to read a bit more about this subjet for PHP.

BR & thanks
Sonnich

>
So let's say checked when:
- $_POST['submit'] is not set
OR
- $_POST[$key] is in the array AND the value isn't empty

$part1 = array('a','b',' c'...........

foreach($part1 as $value){
$checked = (!isset($_POST['submit'] || (isset($_POST[$value]) &&
!empty($_POST[$value])) ? ' checked' : '';
printf('<td><in put type="checkbox" name="%1$s"
value="true"%2$ s>%1$s</td>',$value,$ch ecked');
}

Grtz,
--
Rik Wasmus
Aug 8 '06 #15
Rik
Sonnich wrote:
Rik wrote:
>Sonnich wrote:
>><?
$part1[]="a";
$part1[]="b";
$part1[]="c";
for($i=0; $i<count($part1 ); $i++)
{
echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox \"
value=\"true\ "";
if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
echo " checked";
echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
Euhm, what it this last bit
'isset($_POS T[$part1[$i]])."-".$_POST[$part1[$i]]' actually supposed to do?
It will either print '1-true' or ''(nothing)?

That was meant as debugging :-)
>>."</td></tr>";
}

You've got a submit button, it's name is in the POST array, so it should be
present if the form is posted. Before posting, everything should be checked.
After the posting only the previously left checked values should be checked,
the rest unchecked. Is that how it should work? in that case:

Almost.
In case of any new items, they should be checked too.

There are other options, which might change sql query and by that the
array, so we have new items. They should be selected by default when
they appear.
Otherwise I found this useful.

I'll have to read a bit more about this subjet for PHP.
Well, if we have to check wether the fields existed on the last
page-load, there are several options:
- store the request time, and the date fields get added. This is
somewhat bulky.
- store the available fields in a session, and on reload compare the
session variable with the then available fields.
- add an input type=hidden for every field, containing the name, and on
submit check wether an available name is in the POST array or not.

Grtz,
--
Rik Wasmus
Aug 8 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4810
by: jason | last post by:
Is it possible to POST a FORM to multiple URLS at the same time....OR.... Is the only workaround for this scenario to use response.redirect in the called ASP page and do a multi processing? - Jason
1
5759
by: monika | last post by:
hi ... I have an asp page which has 3 buttons. <p align="center"><input class="button" type="button" onClick="location='welStudent.asp';" value="Click to write a new story"></p> <p align="center"><input class="button" type="button" onClick="location='draftedStory.asp';" value="Click to complete the drafted story"></p> <p align="center"> <input class="button" type="submit" value="Click to view your grade sheet" name="submit"> </p>
2
1871
by: Matt | last post by:
The problem is I have 3 buttons that need to submit the form to different URL. My approach is to declare <input type="submit"> rather than <input type="button">. And put the following in the JavaScript: InputForm.action="URL LOCATION" InputForm.method="POST"; I think we don't need InputForm.submit(); because <input type="submit">.
15
6593
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and the buttons. The problem is when I post a form to itself, the Enter key will not submit the form, it only clears the contents of the text box. The only way I can submit is to click the submit button. Here is a simplified version of my code that I...
1
2805
by: Matt | last post by:
The problem is I have 3 buttons that need to submit the form to different URL. My approach is to declare <input type="submit"> rather than <input type="button">. And put the following in the JavaScript: InputForm.action="URL LOCATION" InputForm.method="POST"; I think we don't need InputForm.submit(); because <input type="submit">.
2
2117
by: Matt | last post by:
The ASP page has multiple buttons, and when the user clicks different buttons, it will submit the form data to different URLs. My first approach was to use BUTTON type, and triggers javascript function to submit the form data. However, it didn't work properly and I changed to use SUBMIT type. <INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search Page" onClick="action1()">
1
6167
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there are no instructions on how to make checkboxes and radio buttons required. I've tried adding these to my form, but I'm having no luck. Anyone know how to add radio buttons and checkboxes using the existing code mentioned on the url? Thank you!
3
1931
by: M | last post by:
i am using submit buttons to send the user to different parts of a wizard. i am using if (if attribute.step1 exists) statements to send them to the appropriate section based on which submit button they pressed. well i would like to change these submit buttons into text links instead. however they do not pass form parameters like the submit button. any simple ways to accomplish this? this is what i have so far:
4
2301
by: wim taerwe | last post by:
Hello, I am looking for an easy way to have a delete button per subitem in 1 form. For example : a book can have many authors and when I edit the book details I want to have a list of the authors each with a separate delete-submitbutton next to it. Now I have the problem that I cannot know which exact author I want to delete when I click the delete button next to it.
5
1820
by: zoomcart.com | last post by:
Hello and thanks in advance for your help. I have code below that posts form data to a cgi scripted shopping cart and it works great on my mac/firefox browser, but it doesn't work on ibm/netscape machines. what gives? apparently the data isn't being recognized and so the cart defaults to it's home page. <form name='submit3' action='http://my.com/cart.cgi' method='post'> <input type='hidden' name='user' value='bighouse'> <input...
0
9944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9796
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10757
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10860
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10420
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9583
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7134
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3239
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.