2

I have a form that visitors to my site can use to sign up for a class. The form is essentially:

<form method="post" action="registration.php">
<h1>Class Name</h1>
<input type="text" name="name">
<input type="email" name="email">
<button type="submit">
</form>

registration.php contains:

 $name = check_input($_POST['name'];
 $name = check_input($_POST['email'];

and some code to email that info. How can I have this also read the Class Name so that I can use that as the subject of the registration email?

Thanks.

3
  • 4
    Is the name of the class provided by PHP? If so, you can pass it as a hidden input. Commented Jun 17, 2013 at 18:23
  • The name of the class is generated by JavaScript. This form is attached to a modal that pops up within a calendar. So the actual header is <h3 name="event" class="EventName"></h3> Commented Jun 17, 2013 at 18:26
  • If you can get an id on that header, you can follow the example here: stackoverflow.com/questions/7764154/… Commented Jun 17, 2013 at 18:29

2 Answers 2

1

There are a few ways you can achieve this.

1) Use a hidden form field (not my favored solution, but you don't have to add as much code)

2) Use an ajax call to submit the form rather than submitting via pure HTML.

For #1 you should add

<input type="hidden" name="class" value="My Class Value">

and then access it via $POST['class']

or

for #2 you could use something like jQuery.ajax()

Sign up to request clarification or add additional context in comments.

1 Comment

I lack the rep to vote you up, so I'll just thank you for the solution, the hidden input worked fine.
0

If the Class Content is given by php you could fill also a hidden input with that information:

<input type="hidden" name="class_name" value="<?php echo $className ?>">

You can also use Javascript.

<h1 class="classname">Class Name</h1>
<input type="hidden" name="class_name" id="classnameinput">
...
<script>
    textClassName = document.getElementById("classname").innerText;
    document.getElementById("classnameinput").value = textClassName;
</script>

Or jQuery...

<h1 class="classname">Class Name</h1>
<input type="hidden" name="class_name" id="classnameinput">
...
<script>
    jQuery(document).ready(function($) {
        textClassName = $('#classname').text()
        $('#classnameinput').val( textClassName );
    });
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.