Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End fields in registration form is not accepting values not even storing value in DB

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #172364
    dnyanesh
    Participant

    Hello,

    i am trying register my detail using this code but fields are not accepting value when i am clicking on send button

    Here is the code
    <?php
    require_once( “common.inc.php” );
    if ( isset( $_POST[“action”] ) and $_POST[“action”] == “register” )
    {
    processForm();
    }
    else
    {
    displayForm( array(), array(), new Member( array() ) );
    }
    function displayForm( $errorMessages, $missingFields, $member )
    {
    displayPageHeader( “Sign up for the book club!” );
    if ( $errorMessages )
    {
    foreach ( $errorMessages as $errorMessage )
    {
    echo $errorMessage;
    }
    } else {
    ?>
    Thanks for choosing to join our book club.
    To register, please fill in your details below and click Send
    Details.
    Fields marked with an asterisk (*) are required.
    <?php } ?>
    <form action=”register.php” method=”post” style=”margin-bottom: 50px;”>

    <input type=”hidden” name=”action” value=”register” />
    <label for=”username” <?php validateField( “username”,$missingFields ) ?> > Choose a username * </label>
    <input type=”text” name=”username” id=”username” value=”<?php echo $member-> getValueEncoded( “username” ) ?>” />
    <label for=”password1″ <?php if ( $missingFields ) echo ‘class=”error”‘ ?> > Choose a password * </label>
    <input type=”password” name=”password1″ id=”password1″ value=”” />
    <label for=”password2″ <?php if ( $missingFields ) echo ‘class=”error”‘ ?> > Retype password * </label>
    <input type=”password” name=”password2″ id=”password2″ value=”” />
    <label for=”emailAddress” <?php validateField( “emailAddress”,$missingFields ) ?> > Email address * </label>
    <input type=”text” name=”emailAddress” id=”emailAddress” value=” <?php echo $member->getValueEncoded( “emailAddress” ) ?> ” />
    <label for=”firstName” <?php validateField( “firstName”,$missingFields ) ?> > First name * </label>
    <input type=”text” name=”firstName” id=”firstName” value=” <?php echo $member-> getValueEncoded( “firstName” ) ?> ” />
    <label for=”lastName” <?php validateField( “lastName”,$missingFields ) ?> > Last name * </label>
    <input type=”text” name=”lastName” id=”lastName” value=” <?php echo $member-> getValueEncoded( “lastName” ) ?> ” />
    <label <?php validateField( “gender”, $missingFields ) ?> > Your gender: * </label>
    <label for=”genderMale” > Male </label>
    <input type=”radio” name=”gender” id=”genderMale” value=”m” <?php setChecked( $member, “gender”, “m” )?> />
    <label for=”genderFemale” > Female </label>
    <input type=”radio” name=”gender” id=”genderFemale” value=”f” <?php setChecked( $member, “gender”, “f” )?> />
    <label for=”favoriteGenre” > What’s your favorite genre? </label>

    <select name=”favoriteGenre” id=”favoriteGenre” size=”1″ >
    <?php foreach ( $member-> getGenres() as $value => $label ) { ?>
    <option value=” <?php echo $value ?> ” <?php setSelected( $member,”favoriteGenre”, $value ) ?> > <?php echo $label ?> < /option >
    <?php } ?>
    </select>
    <label for=”otherInterests” > What are your other interests? </label>
    <textarea name=”otherInterests” id=”otherInterests” rows=”4″ cols=”50″ > <?php echo $member-> getValueEncoded( “otherInterests” )?> </textarea >

    <input type=”submit” name=”submitButton” id=”submitButton” value=”Send Details” />
    <input type=”reset” name=”resetButton” id=”resetButton” value=”Reset Form” style=”margin-right: 20px;” />

    &lt;/form &gt;
    &lt;?php
        displayPageFooter();
    }
    function processForm() {
        $requiredFields = array( "username", "password", "emailAddress","firstName", "lastName", "gender" );
        $missingFields = array();
        $errorMessages = array();
        $member = new Member( array("username" =&gt; isset( $_POST["username"] ) ? preg_replace( "/[^ \-\_a-zA-Z0-9]/", "", $_POST["username"] ) : "","password" =&gt; ( isset( $_POST["password1"] ) and isset( $_POST["password2"] ) and $_POST["password1"] == $_POST["password2"] ) ? preg_replace( "/[^ \-\_a-zA-Z0-9]/", "", $_POST["password1"] ) : "","firstName" =&gt; isset( $_POST["firstName"] ) ? preg_replace( "/[^ \'\-a-zA-Z0-9]/", "", $_POST["firstName"] ) : "","lastName" =&gt; isset( $_POST["lastName"] ) ? preg_replace( "/[^ \'\-a-zA-Z0-9]/", "", $_POST["lastName"] ) : "","gender" =&gt; isset( $_POST["gender"] ) ? preg_replace( "/[^mf]/","", $_POST["gender"] ) : "",
        "favoriteGenre" =&gt; isset( $_POST["favoriteGenre"] ) ? preg_replace( "/[^a-zA-Z]/", "", $_POST["favoriteGenre"] ) : "",
        "emailAddress" =&gt; isset( $_POST["emailAddress"] ) ? preg_replace( "/[^ \@\.\-\_a-zA-Z0-9]/", "", $_POST["emailAddress"] ) : "",
        "otherInterests" =&gt; isset( $_POST["otherInterests"] ) ? preg_replace( "/[^ \'\,\.\-a-zA-Z0-9]/", "", $_POST["otherInterests"] ) : "","joinDate" =&gt; date( "Y-m-d" )
        ) );
    foreach ( $requiredFields as $requiredField ) {
        if ( !$member-&gt; getValue( $requiredField ) ) {
        $missingFields[] = $requiredField;
        }
    }
    if ( $missingFields ) {
        $errorMessages[] = ' There were some missing fields in the form you submitted. Please complete the fields highlighted below and
        click Send Details to resend the form. </p> ';
    }
    if ( !isset( $_POST["password1"] ) or !isset( $_POST["password2"] ) or $_POST["password1"] or !$_POST["password2"] or ( $_POST["password1"] !=$_POST["password2"] ) ) {
        $errorMessages[] = '<p> Please make sure you enter your password correctly in both password fields. </p> ';
    }
    if ( Member::getByUsername( $member-&gt; getValue( "username" ) ) ) {
        $errorMessages[] = '<p> A member with that username already exists in the database. Please choose another username. </p> ';
    }
    if ( Member::getByEmailAddress( $member-&gt; getValue( "emailAddress" ) ) ) {
        $errorMessages[] = ' <p> A member with that email address already exists in the database. Please choose another email address, or contact the webmaster to retrieve your password. </p> ';
    }
    if ( $errorMessages ) {
        displayForm( $errorMessages, $missingFields, $member );
    } else {
        $member-&gt; insert();
        displayThanks();
        }
    }
    function displayThanks() {
        displayPageHeader( "Thanks for registering!" );
    ?&gt;
    <p> Thank you, you are now a registered member of the book club. 
    &lt;?php
        displayPageFooter();
    }
    ?&gt;
    
    #172365
    __
    Participant

    Please don’t do code dumps. Try to narrow it down to the relevant code. If there’s a lot of code, you should post it somewhere else (make a gist on github, for example) because it is difficult -sometimes impossible- to read it here on the forum.

    i am trying register my detail using this code but fields are not accepting value when i am clicking on send button

    This is unclear. What do you mean by “not accepting value”? Do you mean you can’t type into your form fields? the form itself won’t submit (POST)? does register.php not run? does it throw errors? (do you have error reporting enabled?) does the database throw errors?

    Please explain your specific problem in more detail, including what you expect to happen, the code that does that specific part, and what actually happens (including all error info).

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.