/    Sign up×
Community /Pin to ProfileBookmark

Giving users looping access in selecting options.

Hello! Please I would want to be able allow users select options from a list of selections as many times as possible using php, how do i achieve that? Below is a form for better description of what i desire to do

[code=html]
<html><body>
<form action=”” method=”post”>
<p>You can enter your subjects as many times as possible</p>
<select>
<option>English</option>
<option>Mathematics</option>
<option>Physics</option>
<option>Chemistry</option>
<option>Biology</option>
</select>
<select>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<select>
<option>2012</option>
<option>2011</option>
<option>2010</option>
</select>

<Input type=”button” value=”enter”>
</form>
</body>
</html>
[/code]

——————–end
Supposing the user want to enter 5 subjects with their respective grades and year, how do you make the html and php do this jointly or would one require Javascript to do this? Please I need you assistance!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@jedaisoulSep 01.2014 — Looping is no problem, indeed you are already looping the form. What is wrong is:

<i>
</i>&lt;Input type="button" value="enter"&gt;


Should be:

<i>
</i>&lt;Input type="submit" name="submit" value="enter"&gt;


That will submit the form, and, as the action is "", it loops back to itself.

What you need to do is add code to:

a) detect if "submit" has been pressed.

b) if so, process the input.

Something like:
<i>
</i>&lt;?php
if (isset ($_POST['submit'])) {

/* process the input here */

}
?&gt;


You also need to provide a link to somewhere else, as the page will otherwise loop indefinitely!
Copy linkTweet thisAlerts:
@Strider64Sep 01.2014 — You could do it straight in PHP, but you would have to have a separate form where the user would have to answer how many subjects to enter. Then have some kind of loop in the second form repeating the same <select> tag for the subjects. However, using JavaScript would be easier and the page wouldn't have to refresh.
Copy linkTweet thisAlerts:
@jedaisoulSep 01.2014 — @Strider64

I disagree. Looping is the default action of a form, so allowing multiple inputs with PHP is simple. What you do need to do is provide an exit from the loop, e.g. a link to some other web page...

Oh, and I should have mentioned that the select fields need to be named otherwise they will not be included in the POST parameters.
Copy linkTweet thisAlerts:
@erabxesauthorSep 02.2014 — Good Morning guys am grateful for all of your replies. What I really am actually describing is the instance whereby for every complete selection that is made for one entry, that is "Subject"-"Grade"-"Year". The user is now still said to have an option to add another entry as many times as possible because the particular selection entry is designed to re-appear again. Hope I have made myself clearer? A friend advised me to use a "shopping cart mechanism code" to produce what i desire.
×

Success!

Help @erabxes spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...