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.

jabaldonedo
  • 25,822
  • 8
  • 77
  • 77
  • 4
    Is the name of the class provided by PHP? If so, you can pass it as a hidden input. – ಠ_ಠ Jun 17 '13 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 `

    `
    – user2494467 Jun 17 '13 at 18:26
  • If you can get an id on that header, you can follow the example here: http://stackoverflow.com/questions/7764154/pass-a-javascript-variable-value-into-input-type-hidden-value – ಠ_ಠ Jun 17 '13 at 18:29

2 Answers2

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()

Braden
  • 1,548
  • 2
  • 12
  • 20
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>
Axel A. García
  • 683
  • 9
  • 21